Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

The error is ur doing if key.UserInputType

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

1 comment

0

ok i already have saw this error, but thx bro

This discussion is preserved as it was. New answers, comments, and votes are closed.