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

How can I call a localscript from a script?

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?

1 comment

0

Remote events

1 answer

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

1 comment

0

could you demonstrate on how to do local script to script. (edit your resoponce

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