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

How to prevent player movement?

Asked by 6 years ago
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.)

0
The lua formatting on this website messed up the formating... ;(. Sorry hiimgoodpack User#17125 0 — 6y
0
You are binding the functions 10 times a second. That means when you move theres going to be like a thousand functions firing. hiimgoodpack 2009 — 6y
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"? chess123mate 5873 — 6y
0
No, because then if the player is in mid air, it will float. User#17125 0 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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

Ad

Answer this question