Animate Script Bug

So I grabbed the animations script that was locally inside of the player when you join a game, and I just made a new server script and inserted into a NPC I made, but this one error keeps coming up in the output but the whole thing is working fine.

image

This is the line of code that is erroring.

-- setup emote chat hook
game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
	local emote = ""
	if msg == "/e dance" then
		emote = dances[math.random(1, #dances)]
	elseif (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, 0.1, Humanoid)
	end

end)

I think the problem is that you’re using LocalPlayer in a server script

I’ve tried removing it but then it just breaks the whole script unfortunately.

LocalPlayer doesn’t work in server scripts, you would have to use an alternative such as

game:GetService("Players").PlayerAdded:Connect(function(plr)
    plr.Chatted:connect(function(msg)
        -- Rest of your script here
    end)
end)

No, this is an NPC it won’t be chatting at all

Who are you trying to detect a chat message from?

Like I said this is the roblox’s default animation script inside of the player I just pulled

I don’t think I understand, are you trying to make an NPC play an animation when a real player chats a message?

Alright, I am just making the NPC have all the animations a regular player would have, didnt want to have to rewrite code that has already been implemented in the animate script

If you have the animations you can use

local animationTrack = humanoid:LoadAnimation(your animation here)
animationTrack:Play() 

Your current script is only playing animations when the LocalPlayer chats a message, which can only be checked by LocalScripts

1 Like

Alright man it worked thanks for the help!

1 Like