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.
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.
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)