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

How can I pass a value from a Script to a LocalScript using a RemoteFunction?

So I am trying to pass a value from a Script to a LocalScript using a RemoteEvent. So you click a button and an event is fired. Once the LocalScript detects that it then proceeds to run, though I get the following error: "Unable to cast value to Object"

Script

local Active = false
ButtonEvent:FireClient(Active)

LocalScript

ButtonEvent.OnClientEvent:Connect(function(Active)

I am probably being stupid, but I am not 100% with functions yet, so any help is appreciated.

1 comment

0

maybe u have this in ur script but do game:GetService("ReplicatedStorage"):WaitForChild("ButtonEvent") on both of them

2 answers

✓ Accepted answer

FireClient takes in a player object as its first argument. You are passing Active, a bool, as an argument hence the error. If you want to fire the event for a specific player, then do ButtonEvent:FireClient(player, Active). If you want to fire it for all clients, you can do ButtonEvent:FireAllClients(Active) instead.

1 comment

0

Yeah, I just realised as I was testing again, knew it would be me doing something silly. Thanks!

Managed to figure it out, it was being being a little dumb. As I was using RemoteEvent:FireClient:() the first parameter had to be that of the player, instead mine was the value.

So it would fire as:

ButtonEvent:FireClient(Player, Active)

not

ButtonEvent:FireClient(Active)

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