Unable to cast value to object when trying to send a table

Im trying to send a table through from the server to the client using a remote event, something I do in 3 other instances which all work fine, however this one keeps giving me the following error:
image
This is my code:

The print works and shows the correct table as you can see in the first screenshot, the rest of the code is identitcal to what works elsewhere in my game so im really unsure as to why this error occurs specifically for this table

Are you sure it’s specifically the table messing up or the other parameters like Skinweapon or skinequipped?

You didn’t actually fire the remote to a client, you have to specify firstly whom client it should fire to. It wouldn’t be the case if it was RemoteEvent:FireAllClients.

Not sure I understand what you mean?
It fires skinselect which is a remotevent which is then listened to in a local script

Read up on RemoteEvent:FireClient. There’s a parameter that requires a player object.

Then again, I can be wrong and you might’ve already defined the player object.

I didnt even think of that but looking at it then it could be the issue,
skinweapon is this:
image
and so shouldnt be the issue but skinequipped is:
image
which could be nil, im not sure if that would specifically break it

Could you please format this into the forum format ? That would be easier.

I dont see a difference between that and mine

game.Players.PlayerAdded:Connect(function(player) 
	local playerData = game.ServerStorage.PlayerData:WaitForChild(player.Name)
	local skininventory = playerData:WaitForChild("SkinInventory")
	Skinweapon = playerData:WaitForChild("Equipped").Value
	if Skinweapon == "" then Skinweapon = "M4A1" -- default weapon
	task.wait(4) -- enough time for items to load in
	
		Skinselected = skininventory:FindFirstChild(Skinweapon.."Equipped").Value -- finds the value of the skin for the weapon you have equipped
		--^ skinselected selects the skin which is currently equipped to the weapon which is equipped
	
		
		print("skin selected from load = "..Skinselected)
		
		
		
			local skinequipped = playerData.SkinInventory[Skinweapon.."Equipped"].Value 
           
			

		local Inventory1Owned = {}

		for _, Item in ipairs(skininventory:GetChildren())do
			local clientItem = Item:Clone()
			clientItem.Parent = rs.OwnedSkins[player.Name]  -- folder for the player
			table.insert(Inventory1Owned, clientItem.Name)

		end	
print(Inventory1Owned)
		skinselect:FireClient(Inventory1Owned, Skinweapon, skinequipped)

		end	

		wait(2)
		for i,v in pairs(game.ReplicatedStorage.OwnedSkins[player.Name]:GetChildren()) do
			v:Destroy()

		
	end	
end)
1 Like

Can you show the script of the LocalScript that recieves the client event?

This would be firing the table of inventory, the skin weapon, and skinequipped. But there isn’t a player value that it can fire to. So instead it should be:

skinselect:FireClient(player, Inventory1Owned, Skinweapon, skinequipped)

I was under the impression that on the server you dont need to fire the player, as its already done by default?

local function Owned(player, Inventory1Owned, Skinweapon, skinequipped)
	wait(3) 
		
	print(Inventory1Owned) 
	                                                                          
	for i, v in pairs(Inventory1Owned) do
		local WeaponExist = mainframe.skins:FindFirstChild(v)
		if not WeaponExist then continue end -- Doesn't exist
		WeaponExist[i].BorderSizePixel = 3
		WeaponExist[i].BorderColor3 = Color3.fromRGB(0, 170, 0)
		end
	equipped = Skinweapon
	    selected = skinequipped
	    if equipped ~= "" and selected ~= "" then
		script.Parent[equipped]:FindFirstChild(selected).BorderSizePixel = 3
		script.Parent[equipped]:FindFirstChild(selected).BorderColor3 = Color3.fromRGB(255, 255, 127)
	end
end


skinselect.OnClientEvent:Connect(Owned)

This script doesnt occur at all as the error occurs on the server before it can fire the event

I thought that too, I guess it was a lie since I get errors from doing that as well. Well then. You can try to see if it helped at all

2 Likes

FireClient requires a player to be targeted to send the data to as far as I’m aware. Maybe try putting "player, " in front of the parameter list in FireClient to see if that fixes anything?

2 Likes

Yup that seemed to fix that issue, which is strange as it doesnt occur on any other table which doesnt specify player but ends up leading to another error which ill add here rather than making a new post:

Can you copy the section of code that error is coming from and label the line number 219?

	print(Inventory1Owned) -- 217
	                                                                          
	for i, v in pairs(Inventory1Owned) do -- 219
		local WeaponExist = mainframe.skins:FindFirstChild(v)
		if not WeaponExist then continue end -- Doesn't exist
		WeaponExist[i].BorderSizePixel = 3
		WeaponExist[i].BorderColor3 = Color3.fromRGB(0, 170, 0)
		end
	equipped = Skinweapon
	    selected = skinequipped
	    if equipped ~= "" and selected ~= "" then
		script.Parent[equipped]:FindFirstChild(selected).BorderSizePixel = 3
		script.Parent[equipped]:FindFirstChild(selected).BorderColor3 = Color3.fromRGB(255, 255, 127)
	end
end

Do table.concat(Inventory1Owned), if that helps at all.

Try turning the “pairs” in line 219 into “ipairs”