Script throws "Unable to cast value to Object" error when attempting to pass a function through FireClient()

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I wan to pass a function through a remote event’s “FireClient()”

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I googled some stuff but they didn’t work, or fit with my situation.

My code:

--//VARIABLES\\--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Assets = ReplicatedStorage.Assets
local Debris = game:GetService("Debris")
local Animations = Assets.Animations
local Events = Assets.Events

--//FUNCTIONS\\--
function Destroy(object : Instance)
	Debris:AddItem(object, 0)
end
function callback()
	local lighting = game.Lighting:GetChildren()
	for i, lightEffect in pairs(lighting) do
		lightEffect.Parent = ReplicatedStorage.Assets["Disabled Lighting FX"]
	end
end

-- basically some random guy will be teleported to a "place".
-- places in my game are basically maps separated and placed far away from the map.
-- when some stuff happens a random player can be teleported to a place

Events.StartPlaceFunctions.Event:Connect(function(place : Instance, player : Player)
	if place == script.Parent then
		local character = player.Character
		local hrp : Part = character:FindFirstChild("HumanoidRootPart")
		hrp.CFrame = script.Parent.PrimaryPart.CFrame

		
		Events.StartPlaceFunctionsToClient:InvokeClient(callback)
	end
end)

you cant pass functions through

also if you dont want a response back from the client then you should use a remote event with remoteEvent:FireAllClients

you should probably just move the function to the client, but if you have to share the function then put it in a modulescript in replicated storage

I want to use FireClient and not FireAllClients because I want a function to run on a specific client

Will the module script run on the client or the server?

ok move the function to the client and then create a remote event

you can use this from the server:

remoteEvent:FireClient(player)

and then run the function when the event is fired on the client

remoteEvent.OnClientEvent:Connect(callback)

ok i’ll try that

[stuff to bloat this][stuff to bloat this][stuff to bloat this][stuff to bloat this]

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