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

Mind if you can help me with this error called, "Unable to cast value to Object"?

So I have been getting this error called "Unable to cast value to Object" on this script and it says the error is on Line 3 of the server script, mind if you can look over it and see if it can be fixed or maybe some changes? NOTE: A RemoteEvent is in ReplicatedStorage called, "ServerMessageEvent".

SERVER SCRIPT:

game.Players.PlayerAdded:Connect(function(player)
	wait(0.5)
	game.ReplicatedStorage.SystemMessageEvent:FireClient("[Server]: "..player.Name.." has joined the game!")
end)

LOCALSCRIPT:

game.ReplicatedStorage.SystemMessageEvent.OnClientEvent:Connect(function(message)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = message;
		Color = BrickColor.new("New Yeller").Color;
		Font = Enum.Font.Garamond;
		FontSize = Enum.FontSize.Size18;
	})
end)

1 comment

0

A client is perfectly capable of showing text in chat, y'know

2 answers

✓ Accepted answer

RemoteEvents require at least one argument when calling FireClient(), which is the player. In your script, you're not firing the RemoteEvent to any client, just the string. To fix this, simply add the player that joined as the first argument

game.Players.PlayerAdded:Connect(function(player)
    wait(0.5)
    game.ReplicatedStorage.SystemMessageEvent:FireAllClients("[Server]: "..player.Name.." has joined the game!")
end)

edit: missed FireAllClients() somehow

creeper did a good job explaining the issue, but that's not the full answer. You need to make a loop to fire the remote event to every player, just so it goes to all players.

2 comments

0

Oh ok, I tried FireAllClient() and it helped xd.

0

Oh, forgot that was a thing xd

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