"Unable To Cast Value To Object" Error when using clientEvent & serverEvent

Hello, there, another question on this tag system.

When attempting to fire a client event from a server script, it keeps returning the error “Unable To Cast Value to Object”. Unsure as to why it is doing this.

The aim of this, is to be able to give players a unique tag in chat when pressing a button on a GUI. So far, the system is able to display tags in chat, the tag is visible to everyone, but it changes the tag for everyone in the server. Attempting to change it only per-player and ran into this issue.

See Code Below:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Reference both events
local tagEvent = ReplicatedStorage.Events:WaitForChild("FireTag")
local localEvent = ReplicatedStorage.Events:WaitForChild("LocalTag")

local function giveTag(player, tagName, tagColor) -- Recieve tag data from client GUI
	print(player.Name .. " Now has the tag: " .. tagName)
	localEvent:FireClient(tagName, tagColor) -- Fire Client to give tag locally
end

-- Fire Function
tagEvent.OnServerEvent:Connect(giveTag)```

And here is the code in the LocalScript which calls the Client Function:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Get reference to remote event instance
local giveTag = ReplicatedStorage.Events:WaitForChild("LocalTag")


local player = Players.LocalPlayer
local tagFolder = player.PlayerScripts:WaitForChild("ChatTagHandeler")
local tagFold = tagFolder.Tags.Base -- Local storage for player's chat tag info


local function giveTagFunct(tagName, tagColor) -- Pull data from server script to client, change locally
	tagFold.Holder:FindFirstChildWhichIsA("StringValue").Name = tagName
	tagFold.Holder:FindFirstChildWhichIsA("StringValue").Color.Value = tagColor
end

-- Call Function
giveTag.OnClientEvent:Connect(giveTagFunct)```

I think remote functions would be better suited to this as you could request data to be returned from the server

1 Like

To fire a single client you need to pass through the player object as the first parameter so the game knows who to send the event to but as I said previously I don’t think this would be an issue if you used remote functions

1 Like