Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

keybind not working for Stun Skill script, how to fix it?

Asked by 3 years ago

i made a stun script inside a tool, and its not detecting when i press P, whats wrong with my code? all the stun thing i working, i tested it before without using that P bind.

local looping = 0
local tool = script.Parent
local plrs = game:GetService("Players")
local plr = plrs.LocalPlayer
local char = plr.Character
game:GetService("UserInputService").InputBegan:Connect(function(key, processed)
    if processed then return end
    if key.UserInputType == Enum.KeyCode.P then
        if looping == 0 then
                looping = 1
        elseif looping == 1 then
            looping = 0
        end
    end
    -----------------------------------
    while looping == 1 do
        print("Stun Thing bro")
    for _, v in pairs(game.Players:GetChildren()) do
        wait(.1)
        if v.Character ~= char then
            if (v.Character.Head.Position - char.Head.Position).magnitude <=15 then
                v.Character.Humanoid.WalkSpeed = 1
                v.Character.Humanoid.JumpPower = 0
            elseif (v.Character.Head.Position - char.Head.Position).magnitude >15 then
                v.Character.Humanoid.WalkSpeed = 16
                v.Character.Humanoid.JumpPower = 50
            end
        end
    end
    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

The error is ur doing if key.UserInputType

Thats not how you compare keycodes, do this instead if key.KeyCode

0
ok i already have saw this error, but thx bro Ariirael 15 — 3y
Ad

Answer this question