Script not freezing player after reset

I’m trying to make the player freeze and play an animation every time a button is pressed, and when pressed again, the animation should stop. That part works.

The part that doesn’t work is whenever the player is reset, either through commands or normally,

  1. the player will have to press the button twice just for the animation to actually play and
  2. the player will still be able to move during the animation

Here’s the local script where I think the error might be:

local EmotesFrame = script.Parent
local innerFrame = EmotesFrame.InnerFrame
local Input = game:GetService("UserInputService")
local module = require(game.ReplicatedStorage.Variables)
local player = game.Players.LocalPlayer
local character = player.Character
local animated = false

innerFrame.Back.MouseButton1Click:Connect(function()
	EmotesFrame.Visible = false
end)

innerFrame.Lay.MouseButton1Click:Connect(function()
	if animated == false then
		local human = character:WaitForChild("Humanoid")
		local anim = innerFrame.Lay.Animation
		human.WalkSpeed = 0
		human.JumpPower = 0
		game.ReplicatedStorage.Animation:FireServer(anim, animated)
		animated = true
	else
		local human = character:WaitForChild("Humanoid")
		local anim = innerFrame.Lay.Animation
		human.WalkSpeed = 16
		human.JumpPower = 50
		game.ReplicatedStorage.Animation:FireServer(anim, animated)
		animated = false
	end
end)

innerFrame.Sit.MouseButton1Click:Connect(function()
	if animated == false then
		local human = character:WaitForChild("Humanoid")
		local anim = innerFrame.Sit.Animation
		human.WalkSpeed = 0
		human.JumpPower = 0
		game.ReplicatedStorage.Animation:FireServer(anim, animated)
		animated = true
	else
		local human = character:WaitForChild("Humanoid")
		local anim = innerFrame.Sit.Animation
		human.WalkSpeed = 16
		human.JumpPower = 50
		game.ReplicatedStorage.Animation:FireServer(anim, animated)
		animated = false
	end
end)

And, I doubt this is the problem, but I’ll include the serverscript, too, just in case:

game.ReplicatedStorage.Animation.OnServerEvent:Connect(function(player, animation, animated)
	local anim
	print(tostring(player), tostring(animated), tostring(animation))
	if animated == false then
	 	local character = player.Character
		local human = character:WaitForChild("Humanoid")
		anim = human:LoadAnimation(animation)
		anim:Play()
	else
		local character = player.Character
		local human = character:WaitForChild("Humanoid")
		for _,thisTrack in pairs (human.Animator:GetPlayingAnimationTracks()) do
			thisTrack:Stop()
		end
	end
end)

try putting the localscript into StarterCharacterScripts if it already isn’t, this is cause each time you respawn, the character variable doesnt actually update to the player’s new character

alternatively u could also just try using player.Character over making a character variable

1 Like

It’s already in starter gui because it’s in the same gui as a button, so I can’t move it to starter character scripts. However, changing it all to “player.Character” rather then a variable seems to fix the problem of the animations not freezing the player. Problem is, the first problem still is here, and I know that it’s because the “animated” variable doesn’t reset when the player is reset, but I just don’t know how fix it.

(Also this is probably obvious but this only happens when the player resets through admin or through roblox’s normal reset WHILE the animation is still playing)

Why don’t you just loop through body parts of the player and set their Anchored to true ?

Also i have a better solution for freezing the player

I don’t want players stacking on top of each other, also I still don’t think that’d solve the problem anyway.

This is how i freeze players without using their speed

local mod = require(game.Players.LocalPlayer:WaitForChild('PlayerScripts'):WaitForChild('PlayerModule'))
local control = mod:GetControls()
control:Disable()

And if u want to let them move again just do control:Enable()

Well I already fixed that problem, although I might change to that solution, but my problem now is that they have to click the button twice after resetting so that “animated” gets set back to false on the first click and then actually animates like normal on the second click. Should only be one click.

nevermind, fixed it using player:CharacterAdded

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.