I am making a live event, when it starts I want to fire a local script to all players, in a script. Can I call the local script and will execute on all clients?
In this case it is a cutscene local script.
You can use RemoteEvent:FireAllClients(…) and have the cutscene localscript listening to that RemoteEvent (RemoteEvent.OnClientEvent)
In the (…) aka … is that where the localscript is
that’s where you put any parameters you need
You can call Remote:FireAllClients() and call any callback on the client alongside a listener.
-- server
RemoteEvent:FireAllClients()
-- client
local function OnClient()
end
RemoteEvent.OnClientEvent:Connect(OnClient)
There is a way to do so, and it’s by using something called a RemoteEvent.
In the ServerScript, you can call RemoteEvent:FireAllClients()
which will fire a remote event to all clients (all players) in the game. Make sure that you either have a variable for RemoteEvent
or you reference to it in your :FireAllClients()
line.
In your LocalScript, you will have to write what you want to happen when the client event is fired. The way you would do so is by doing something such as:
local RemoteEvent = game.ReplicatedStorage.RemoteEvent
local function liveEvent() -- you can change the name of the function to whatever you want.
-- write code that you want to be run when the event is fired inside here.
end
RemoteEvent.OnClientEvent:Connect(liveEvent) -- make sure the function name inside the () matches the function name from above.
Hopefully this was helpful.