Disable player all animation temporarily

  1. What do you want to achieve?
    In my game, i have elevators my elevators weld the player to it so i need to pause all player animations and prevent the player to do emotes.
    And i need to reactivate them back after the elevator arrive at his floor.
    The script that manage the elevator is in the model of the elevator.

  2. What is the issue?
    I can’t manage to do it.

  3. What solutions have you tried so far?
    I tried myself and looked on forums.

1 Like
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

for _, track in ipairs(humanoid:GetPlayingAnimationTracks()) do
	track:Stop()
end
2 Likes

How can i do it with a table because my players that are in the elevator is stored in a table

In a localscript

You can do:

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, false)-- set to false

To disable the emote menu

and you can do:

local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.EmotesMenu, true)-- set to true

to enable the emote menu

for _, player in pairs(elevatorPlayers) do 
	local character = player.Character 
	if not character then continue end 
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if not humanoid then continue end 
	for _, track in pairs(humanoid:GetPlayingAnimationTracks()) do 
		track:Stop()
	end
	--and to disable new animations from running:
	local animator = humanoid:FindFirstChildWhichIsA("Animator")
	if not animator then continue end
	animator.AnimationPlayed:Connect(function(track)
		track:Stop()
	end)
end

You can also edit the “Animate” local script in the player’s character to prevent the use of default emotes.

You can edit the “Animate” local script in the player’s character and add this:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local canEmote = Player:WaitForChild("CanEmote")--Boolvalue stored in player
local connection

function onPlayerChatted(msg)
	local emote = ""
	if (string.sub(msg, 1, 3) == "/e ") then
		emote = string.sub(msg, 4)
	elseif (string.sub(msg, 1, 7) == "/emote ") then
		emote = string.sub(msg, 8)
	end

	if (pose == "Standing" and emoteNames[emote] ~= nil) then
		playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
	end	 
end

connection = Player.Chatted:connect(onPlayerChatted)

canEmote.Changed:Connect(function()
	if canEmote.Value == false then
		connection = Player.Chatted:connect(onPlayerChatted)
	else --if canEmote == true
		connection:Disconnect()
	end
end)

and delete this at line 739:

-- setup emote chat hook
game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
	local emote = ""
	if (string.sub(msg, 1, 3) == "/e ") then
		emote = string.sub(msg, 4)
	elseif (string.sub(msg, 1, 7) == "/emote ") then
		emote = string.sub(msg, 8)
	end
	
	if (pose == "Standing" and emoteNames[emote] ~= nil) then
		playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
	end
end)

Here is the animate local script put it in StarterPlayer > StarterCharacterScripts and apply what I suggested before.