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

How do I call something from a local script(GUI script) to happen from a server script?

Asked by 6 years ago

This question may be stupid; the answer may be staring me in the face or it may be complicated - Honestly, I don't know.

So, I have made a GUI script in a local script inside of one of the GUIs inside of StarterGUI

I have also made a normal script which lives inside of ServerScriptService.

The normal script is the main script for the game and is all inside one loop -while true do

In the local GUI script I have programmed a GUI to pop up

I want the GUI to pop up at a certain time in the main script

How would I do that?

I have tried making a global function inside the GUI script and then calling the function inside the main script, but it gives me the error: attempt to call field 'Pizza' (a nil value)

(yes, I named my function Pizza)

I also tried making an if statement and making the condition true in the main script so that the GUI script would trigger when the condition was true but it simply didn't work -no errors.

There are no errors within the main script itself and there are no errors within the GUI script itself It just doesn't work when I try connecting the scripts in any way.

I hope everything I said makes sense.

Thanks, xAdeline

0
Yes, you will have to look into using RemoteEvents or RemoteFunctions which allow the Server (Scripts) and the Clients (Local Scripts) to communicate with eachother. http://wiki.roblox.com/index.php?title=Remote_Events_and_Functions xPolarium 1388 — 6y
0
Oh okay, Thank you very much xPolarium! I looked into remote funcitons and events but I didnt want to go too far into it without knowing for sure that's what needed to be used. Thanks again! xAdeline 2 — 6y
0
GOOD PRACTICE: DON'T BEGIN FUNCTION NAMES WITH CAPITAR LETTER, USE small INSTEAD. Classes names should begin with Capital letters. ErtyPL 129 — 4y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

Always look for the wiki page that has what you're looking for.

In the server script:

re = Instance.new("RemoteEvent", workspace)
re.Name = "GuiTrigger" -- Try a different name
-- In a different script
re:FireClient(game.Players.SebbyTheGODKid)

In the GUI script:

re = workspace:WaitForChild("GuiTrigger")
re.OnClientEvent:connect(function()
    -- My code here...
    print("my remote event got fired!")
end)
0
Thank youir very much SebbyTheGODKid; This script is extremely helpful! xAdeline 2 — 6y
0
You're welcome. Please accept my answer if it answers your question. SebbyTheGODKid 198 — 6y
Ad

Answer this question