#Restricting a skill and NPC spawning issue

34 messages · Page 1 of 1 (latest)

plain stream
#

I'm trying to restrict a "Skill" which can be activated by pressing the Skill Icon using m1 and keyCode.one but for some reason this code isn't working

UserInputService.InputBegan:Connect(function(input, event)
local keyBind = input.KeyCode == Enum.KeyCode.One
local clickBind = input.UserInputType == Enum.UserInputType.MouseButton1 
    if event then return end
    if keybind or clickBind then -- check keybinds
        toggleEquip()
    elseif clickBind and equipped then
        -- some animation code here
    end
end)

but if I stick with:

if keyBind then -- check keybinds
toggleEquip()
elseif clickBind and equipped then
-- some animation code here
end

it only works if I use "1" key, anything I can do? if so please point out my mistakes.

#

Restricting a skill and NPC spawning issue

#

Also, i have a script file in ServerScriptService which is:

covert bloom
#

keybindOne is not a thing

plain stream
#

but something's wrong...

  • sometimes the script is not getting triggered
covert bloom
#

equipped isnt a thing either

#

(unless ur not showing the whole code)

plain stream
#

imma drop the real code here jsyk

UserInputService.InputBegan:Connect(function(input, event)
    if event then return end
    if input.KeyCode == Enum.KeyCode.One then
        toggleEquip()
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
        local currentTime = tick()
        if currentTime - lastPunchTime >= cooldownTime then
            cycleAnimation()
            playAnimation()
            lastPunchTime = currentTime
            local character = Players.LocalPlayer.Character
            if character then
                local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
                if humanoidRootPart then
                    local region = humanoidRootPart.Position
                    local npcFolder = game.Workspace.MobNPC
                    for _, npcTypeFolder in pairs(npcFolder:GetChildren()) do
                        if npcTypeFolder:IsA("Folder") then
                            for _, npc in pairs(npcTypeFolder:GetChildren()) do
                                local humanoid = npc:FindFirstChild("Humanoid")
                                if humanoid then
                                    local distance = (npc.PrimaryPart.Position - region).Magnitude
                                    if distance <= 5 then
                                        applyDamageToNPC(npc)
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end
    end
end)
#

i manually typed it which leads to typo

covert bloom
#

equipped still isnt a thing

#

😔

plain stream
honest steepleBOT
#

studio** You are now Level 2! **studio

plain stream
#

here

plain stream
covert bloom
#

you know

#

doing damage scripts in a local script is rlly rlly buggy

#

and i 100% not recommend it

#

so that might be the issue

plain stream
#

oh srsly?! maybe that's my problem...

plain stream
#

like a combo of files, cuz im still new with the roblox studio. ive read some docs but i think im still lost

covert bloom
#

cut off half of the script and move it into a normal script and make a local script fire a remote event

#
UserInputService.InputBegan:Connect(function(input, event)
    if event then return end
    if input.KeyCode == Enum.KeyCode.One then
        toggleEquip()
    elseif input.UserInputType == Enum.UserInputType.MouseButton1 and equipped then
        remoteevent:FireServer()
    end
end)
#

then in a normal script

#
remoteevent.OnServerEvent:Connect(function()
plain stream
#

quick question, where should i put the remoteEvent and the normal script?

#

i think i understood your point

covert bloom
#

it should work anywhere

plain stream
#

hb remote? still inside local script?

covert bloom
#

yeah

plain stream
#

i see