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

Is there a way to comunicate between scripts?

Asked by 4 years ago

I need to communicate from a regular script in serverscriptservice to a local script in starter gui. I dont have any experience with remote functions and events. im making a story game so i really need to know how to do this. any thoughts would help.

0
if it helps at all, im trying to call a function thats in a local script frm a regular script super00rocket 27 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

Yes. Multiple ways, you could use module scripts that can store info on what to run and call it from another script, or you could use a remote event. Remote events can be ran by something like this:

local event = game.ReplicatedStorage.Event
event:FireServer()

You can tell something to happen when this is activated by:

local event = game.ReplicatedStorage.Event

event.OnServerEvent:Connect(function()
print("Event fired")
end)

Hope this helped!

0
^^^ THUNDER_WOW 203 — 4y
0
That may have shortend my number of YT videos i need to watch by like a million super00rocket 27 — 4y
0
Thanks! super00rocket 27 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Your only answer kinda really is RemoteEvents. You could use ModuleScripts but they are usually used for tables and must return one value. You should try to learn on how they work by other people's posts and devforums, etc. The devhub can be confusing so I'll make an example for you.

--Client script (script in gui)
local lplayer = game.Players.LocalPlayer --Grab the player
script.Parent.MouseButton1Click:Connect(function() --Let's say a play button is pressed
    game.ReplicatedStorage.RemoteEvent:FireServer(lplayer) --Send the player as a parameter
end)
--Serverscript
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, lplayer)
    local TP = game:GetService("TeleportService")
    TP:Teleport(1234567890, lplayer) --teleport the player who clicked the button
end)
0
That is a great example above. THUNDER_WOW 203 — 4y
0
Thanks that will for sure come in handy! super00rocket 27 — 4y

Answer this question