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

Error: Unable to cast value to Object when firing remote event?

I am trying to fire the remote event "PlayAudioLocal" in my server script but I get the error: Unable to cast value to Object

Server

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local playAudio = ReplicatedStorage:WaitForChild("Remotes"):FindFirstChild("PlayAudioLocal")

playAudio:FireClient("PurchaseComplete")

Local

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local playAudioLocal = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("PlayAudioLocal")
local audio = ReplicatedStorage:WaitForChild("Audio")

playAudioLocal.OnClientEvent:Connect(function(name)
	print("Fired")
	if audio:FindFirstChild(name) then
		audio[name]:Play()
	else
		warn("Could not find " .. name .. " in ReplicatedStorage/Audio")
	end
end)

1 answer

✓ Accepted answer

The first argument of FireClient is the player (client) that you are firing to. You've only passed a string (the "value" mentioned in the error message) when an object (the player) is expected to be the first argument.

Since it doesn't look like there's any player for you to reference there, it looks like you might be meaning to call FireAllClients instead.

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