Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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.

0
maybe u have this in ur script but do game:GetService("ReplicatedStorage"):WaitForChild("ButtonEvent") on both of them Gameplayer365247v2 1055 — 5y

2 answers

Log in to vote
1
Answered by
RayCurse 1518 Moderation Voter
5 years ago

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.

0
Yeah, I just realised as I was testing again, knew it would be me doing something silly. Thanks! ConnorThomp 87 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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)

Answer this question