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

Is there a way to comunicate between scripts?

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.

1 comment

0

if it helps at all, im trying to call a function thats in a local script frm a regular script

2 answers

✓ Accepted answer

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!

3 comments

0

^^^

0

That may have shortend my number of YT videos i need to watch by like a million

0

Thanks!

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)

2 comments

0

That is a great example above.

0

Thanks that will for sure come in handy!

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