Unable to cast value to Object

I’m trying to fire a client script but this error shows up. It’s simple but I couldnt find the solution

Here’s the code and error:

local function removePlayer(playersList, player, i)
table.remove(playersList, i)
			print(player.Name .. " has been removed")
			
			if player or player.Character then
				ChangeVisibility:FireClient(player, "PlayerStats", false)
				
				if player.Character.Humanoid and player.Character.Humanoid:FindFirstChild("Creator") then
					local text = player.Character.Humanoid.Creator.Value .. " has killed " .. player.Name
					Killfeed:FireClient(playersList, text)
				else
					local text = player.Name .. " has fallen..."
					Killfeed:FireClient(playersList, text) -- error is in this line
				end
				
			else
				Killfeed:FireClient(playersList,player.Name .. " has left the game...")
			end
		end

If that value is an ObjectValue then you should do

player.Character.Humanoid.Creator.Value.Name

What line of code did the error happen on?

ill edit this post in just a moment

What does the error you’ve got say?

Killfeed:FireClient(playersList, text) -- error is in this line

ohh wait sorry, i didnt see the title.
So, are you sure the “Killfeed” variable is RemoteEvent? because killfeed variable could be something that isnt remoteevent.
if that isn’t the issue, then you might check the script that receives the remoteEvent which made the error.

The error is:

Unable to cast value to Object

This means that the function expected an Object, and got a value (table). It can’t use a value as an Object. To fix the error, you should iterate the list and fire each player individually. If you want to tell all clients this, use :FireAllClients().

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.