guys, im making a stun skill what if i press P if get active and keep looking for ppl what get close to me for stun them, and if i press P again it stop look for ppl, but its not working, can you guys see my script pls?

game.ReplicatedStorage.StunThingP.OnServerEvent:Connect(function(player)
	local UIS = game:GetService("UserInputService")
local looping = false

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.P then
		if looping == false then
			looping = true
			while looping == true do
	for _, v in pairs(game.Players:GetPlayers()) do
						print("stun hmmmm!")
		if v.Character ~= player.Character then
			if (v.Character.Head.Position - player.Character.Head.Position).magnitude <=15 then
				v.Character.Humanoid.WalkSpeed = 1
				v.Character.Humanoid.JumpPower = 0
			elseif (v.Character.Head.Position - player.Character.Head.Position).magnitude >15 then
				v.Character.Humanoid.WalkSpeed = 16
				v.Character.Humanoid.JumpPower = 50
			end
		end
			end
						
			end 
				if inp.KeyCode == Enum.KeyCode.P then
							looping = false
						end	
			end
		end
	end)
end)

3 comments

0

im using a LocalScript to detect when i press P and activating a RemoteEvent, should i use this or i can make this skill in just a single script? i want make it "giveable", for i give it just for me.

0

What is the problem? Is it not starting at all? Is it not stopping? Is it not looping? I can't exactly help if I don't know the specifics of the problem.

0

its not starting when i tried to made that loop function, then.. isnt looping too.