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

Why do I get an error that says "Unable to cast value to Object"?

So what I am basically doing in my server script is a "for" loop that loops through a table with the players' names and in that "for" loop, it will fire the player's name to the client. Here is the code:

local list = {}
for i = 1, #list do
	if game.Players:FindFirstChild(list[i]) then
		game.ReplicatedStorage.Remotes.MorePlayersNeeded:FireClient(list[i]) -- Error
	end
end

1 answer

✓ Accepted answer

You need to pass a player instance to :FireClient, but you were passing player name

local list = {}
for i = 1, #list do
    local plr = game.Players:FindFirstChild(list[i])
    if plr then
        game.ReplicatedStorage.Remotes.MorePlayersNeeded:FireClient(plr)
    end
end

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