Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

free model goes localplayer, in a server script. how do i fix it?

so because I'm lazy and I can't be bothered making an r15 noob, I dragged one in from the toolbox. eazy. the thing is this character had an animate script. helps me a lot. problem is, whenever I run the game, it says attempt to index local player, a nil value. yes, its in a server script. I would like it to work in case its critical, so can you guys help with a solution? :D
code:

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, 0.1, Humanoid)
	end
end)

thanks!

1 answer

✓ Accepted answer

Issues

the LocalPlayer can only be called on LocalScripts, however, you can get the player on the server with the .PlayerAdded event of the Players Service

Revised Server Script

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.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, 0.1, Humanoid)
		end
	end)
end)

1 comment

0

thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.