Hello! I am making a system in my game where you can say “/e cry” or any other animations I have and it will load the animation on the player, so I made a server script and added this code:
Have you tested this in the roblox client? Chat in roblox studio is kinda buggy currently.
Also make sure nothing yields the Player.PlayerAdded for too long or the player will join before the function is hooked.
If you do have something yielding, you can just loop through the players currently ingame and make the Chatted a function.
It is your preference if you want to do it on the client or not.
If you do it on the client do
game:GetService(“Players”).LocalPlayer.Chatted:Connect(function()
If all you’re doing is playing a corresponding animation for the emote command, you don’t need client-to-server communication in order to play the animation. Load the animation onto the Animator, the animations will automatically replicate to other clients. You don’t want input lag on your client. Always do your visuals on the client.
I am trying to do this, but it does not work. There are no errors:
game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
if msg:lower() == "/e sit2" then
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local animator = humanoid:FindFirstChildOfClass("Animator")
local track = animator:LoadAnimation(sit)
track:Play()
end
end)
You need to call animator:LoadAnimation() on an Animation
game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
if msg:lower() == "/e sit2" then
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local animator = humanoid:FindFirstChildOfClass("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = "animationid here"
local track = animator:LoadAnimation(Animation)
track:Play()
end
end)
Not sure if you were calling it on an animation already or not.
If you were already calling it on an animation, the id could be wrong.
game:GetService("Players").LocalPlayer.Chatted:Connect(function(msg)
if msg:lower() == "/e sit2" then
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local animator = humanoid:FindFirstChildOfClass("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = 6384257999
local track = animator:LoadAnimation(Animation)
track:Play()
end
end)
And it gives an error saying that it has an invalid animation ID.