i want make a Tool with a script inside what can be a Proximity Stun, like if i press "P" it activate and when players get close to me, they are stunned, and it i press P again, it deactivate. i made a script to test the proximity thing, but it dont work, it this:
local players = game.Players
local player = script.Parent.Parent.Parent
local stuncooldown = false
local char = player.Character
while true do --loop so it repeatedly occurs
if stuncooldown == false then
stuncooldown = true
spawn(function() --so that it occurs approximately once per second
wait(1)
stuncooldown = false
end)
for i, v in pairs(players:GetChildren()) do
if (v.Character.Head.Position - char.Head.Position).magnitude <=10 then
v.Character.Humanoid.WalkSpeed = 1
v.Character.Humanoid.JumpPower = 0
spawn(function()
wait(.5)
--below here to unstun player after X seconds
v.Character.Humanoid.WalkSpeed = 16
v.Character.Humanoid.JumpPower = 50default
end)
end
end
end
end

2 comments
Use UserInputService.
how?