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

How to prevent player movement?

while true do
	wait(0.1)
	if game.Players.LocalPlayer.leaderstats.Stop.Value == 1 then
		RunService:BindToRenderStep('Control', Enum.RenderPriority.Input.Value, 
                onUpdate)
		ContextActionService:BindAction('Left', onLeft, true, 'a', Enum.KeyCode.Left, 				
                Enum.KeyCode.DPadLeft)
		ContextActionService:BindAction('Right', onRight, true, 'd', Enum.KeyCode.Right, 		
                Enum.KeyCode.DPadRight)
		ContextActionService:BindAction('Jump', onJump, true, 'w', Enum.KeyCode.Space, 
 		Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
        end
	if game.Players.LocalPlayer.leaderstats.Stop.Value == 0 then
		print("SSSSSS")
		RunService:BindToRenderStep('Control', Enum.RenderPriority.Input.Value, 
                onUpdate)
		ContextActionService:BindAction('Left', onLeft, false, 'a', Enum.KeyCode.Left, 	
 		Enum.KeyCode.DPadLeft)
		ContextActionService:BindAction('Right', onRight, false, 'd', Enum.KeyCode.Right, 
 		Enum.KeyCode.DPadRight)
		ContextActionService:BindAction('Jump', onJump, false, 'w', Enum.KeyCode.Space, 
  		Enum.KeyCode.Up, Enum.KeyCode.DPadUp, Enum.KeyCode.ButtonA)
	end
end

So, this script it's supposed to not allow player movement if a leaderstat called "stop" == 0. It's a snippet of a larger script, but this is all that really matters.

Yes, it does register whenever the value is changed i checked.

Can someone tell me what i did wrong here?

PS ( Yes hiimgoodpack, I indented specifically so you wouldn't put me on your kill list.)

4 comments

0

The lua formatting on this website messed up the formating... ;(. Sorry hiimgoodpack

0

You are binding the functions 10 times a second. That means when you move theres going to be like a thousand functions firing.

0

Couldn't you just get the local player's HumanoidRootPart and, if it exists, set its .Anchored to "game.Players.LocalPlayer.leaderstats.Stop.Value == 1"?

0

No, because then if the player is in mid air, it will float.

1 answer

Disable Player.PlayerScripts.ControlScript using a LocalScript already inside it.

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