How could I completely freeze a player's movement, then return it

I am looking to make a player’s movement stop completely so an animation can play, then have their movement return once it has completed.

I tried setting their WalkSpeed to 0 and this didn’t work, and I am not going to anchor their HRP due to their walking animations still playing if they use WASD (I assume).

1 Like

Why didn’t the walkspeed work? Try setting jumpPower to 0 aswell and wait after the animation is done.

1 Like

Anchoring their HRP actually worked, but I have no idea why the walkspeed didn’t work. I used print to print their walkspeed before and after the animation was ran and they printed 0.

1 Like

Are you setting their walkspeed on the server?

1 Like

No, I am guessing that’s the issue. Should I be using a RE?

Yes. That is the issue. Try that and get back to me. You should be using a RE

2 Likes

So I wrote a LS and SS and the RE event isn’t working, here are my scripts:

-- Local script
local RS = game.ReplicatedStorage
local RE = RS:WaitForChild("AnimationEvent")

local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local PointAnim = script:WaitForChild("Point")
local PointTrack = Humanoid:LoadAnimation(PointAnim)

RE:FireServer(PointTrack, Humanoid)
-- Server script
local RS = game.ReplicatedStorage
local RE = RS:WaitForChild("AnimationEvent")

RE.OnServerEvent:Connect(function(Player, Track, Humanoid)
	Humanoid.WalkSpeed = 0
	Track:Play()
	wait(5)
	Humanoid.WalkSpeed = 16
end)

I am apparently indexing nil with Play().

You can’t play animations in server scripts.

What? Why did you ask me if I was using it on the serve then? I assumed you wanted me to use the anim on the server…

Edit: Okay you never said run the anim on the server, only the walkspeed…
How would I allow the whole server to see my animation if I can’t run it on the server?

Animations are serversided even on the client. You can see that from exploiters, as exploiters are on the client. The animations will still be seen on the server even if they are on the client.

1 Like

Is there a more efficient way of waiting for the animation to finish to reset the player’s walkspeed and jumpspeed? Right now I am just using the animation length (wait(5)), there must be a better way.

The PlayerModule has functions for disabling inputs.

local PlayerModule = require(game:GetService('Players').LocalPlayer.PlayerScripts:WaitForChild('PlayerModule'))

local controls = PlayerModule:GetControls()

-- to disable controls
controls:Disable()

-- to enable controls
controls:Enable()
2 Likes

There is a property in animations that show you the length of it (I think) so you could just do wait(Ani.length) or something like that.

AnimationTrack.Stopped

Exactly what i was looking for, thanks!

1 Like

How am I meant to use .Stopped if I can’t pass the track as a parameter or use it in a local?

You fire to the server, play it and use this line to wait until its stopped.

animationTrack.Stopped:wait()

After fire to the server back to give back the walkspeed.
The animations should be on the client. So this should work on the client.

AnimationTrack:Play replicates from client to server as long as the animator was created on the server, which it was if you’re using Roblox’s default characters.

You can do this entirely on client:

  1. Require PlayerModule like so:
    local PlayerModule = require(game:GetService('Players').LocalPlayer.PlayerScripts:WaitForChild('PlayerModule'))
    
  2. Get the controls:
    local controls = PlayerModule:GetControls()
    
  3. Disable them:
    controls:Disable()
    
  4. Play the animation and wait until it finishes:
    track:Play()
    track.Stopped:Wait()
    
  5. Re-enable the controls:
    controls:Enable()
    

All of this can be done on the client with no RemoteEvents required.

6 Likes

Wow that looks much cleaner, and it’s shorter. Thank you.

1 Like

You should be waiting for the “PlayerScripts” folder to replicate as this is a local script, otherwise the script could potentially error.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerScripts = Player:WaitForChild("PlayerScripts")
local PlayerModule = PlayerScripts:WaitForChild("PlayerModule")
local Module = require(PlayerModule)
3 Likes