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.
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!
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)