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

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

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

3 comments

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

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!

0

GOOD PRACTICE: DON'T BEGIN FUNCTION NAMES WITH CAPITAR LETTER, USE small INSTEAD. Classes names should begin with Capital letters.

1 answer

✓ Accepted answer

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)

2 comments

0

Thank youir very much SebbyTheGODKid; This script is extremely helpful!

0

You're welcome. Please accept my answer if it answers your question.

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