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

How can I call a localscript from a script?

Asked by 5 years ago

ok so i'm trying to run a localscript inside of a script however i can't figure out how.. can someone help?

basically i have a round script and i want it to play a cutscene of the map which the cutscene is stored in a localscript but how would i execute that script using the round script?

0
Remote events User#19524 175 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This is where remote events come in. Start by inserting a Remote Event into ReplicatedStorage. Now, you use :FireClient() and .OnServerEvent. (If you're tying a Server Script TO a LocalScript, use :FireClient() and OnClientEvent. If you're tying a Local Script, to a Server Script, use :FireServer() and OnServerEvent.) To do this, say this was you're regular script (Make sure its somewhere that can run Server Scripts):

game.Players.PlayerAdded:Connect(function(player)
print("Test")
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireClient(player)  --This is where the magic happens
end)

Now what you do, is you make your local script listen for that Fire. And when it hears it, it will do what you want the Local Script to do (Make Sure its somewhere that can run LocalScripts).

game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnClientEvent:Connect(function() -- This is what makes it listen for the fire
-- Do whatever u want the local script to do, exp: Change Guis.
end)

Any questions leave down below and ill answer em, make sure to accept if I helped :)

0
could you demonstrate on how to do local script to script. (edit your resoponce astroblox17 -11 — 4y
Ad

Answer this question