Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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)
0
A client is perfectly capable of showing text in chat, y'know hiimgoodpack 2009 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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

Ad
Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
6 years ago

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.

0
Oh ok, I tried FireAllClient() and it helped xd. CounterBoy123 53 — 6y
0
Oh, forgot that was a thing xd H4X0MSYT 536 — 6y

Answer this question