Sprint Script Cancels Immobility ~ Help

So what I am trying to achieve right now is while an animation is playing, the player cannot move, they’re immobile. BUT, I have a sprint script and it’s making it easy for the player to cancel the immobility because it’s adding to the player’s WalkSpeed
For example

Humanoid.WalkSpeed = 0 --When Immobile.

--But

Humanoid.WalkSpeed = 35 --When Sprinting

So if you still don’t get it, basically when the player is doing the animation, their Humanoid WalkSpeed is 0. But the player can easily just press shift to just cancel the WalkSpeed = 0 and turn it into 35 because that’s the speed for the sprint. I’ve tried

workspace.SprintScript.Disable = true 

But it doesn’t work because when the game starts the script automatically gets duplicated into the payer’s PlayerScripts. How can I stop this from happening? Or at least disable it temporarily

In the sprint script you could check to see if the player is immobile. If they are not immobile then change the walkspeed. Something like this should work

if not (Humanoid.WalkSpeed == 0) then
    Humanoid.WalkSpeed = 35
end

I’ll give you my script because I don’t know where I would put that at

repeat wait() until game.Players.LocalPlayer

local m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)
	                            
	if key == "0" then
 --I'm guessing I'd put it right here? (if not game.Players.LocalPlayer.Humanoid.WalkSpeed == 0 then)
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 35
	end
end)

m.KeyUp:connect(function(key)
	if key == "0" then
		                                   
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 20
	end
end)

You have to do it inside the keydown and keyup event. It would look something like this

repeat wait() until game.Players.LocalPlayer

local m = game.Players.LocalPlayer:GetMouse()

m.KeyDown:connect(function(key)
	                             --I'm guessing I'd put it right here? (if not game.Players.LocalPlayer.Humanoid.WalkSpeed == 0 then)
	if key == "0" then
        if not (game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 0) then
            game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 35
        end
	end
end)

m.KeyUp:connect(function(key)
	if key == "0" then                     
        if not (game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 0) then -- or here you could use  if game.Players.LocalPlayer.Character.Humanoid.WalkSpeed == 35 then
		    game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 20
        end
	end
end)
1 Like

Thanks a lot! This worked for me.