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

Any way to stop a Remote Function within a loop? (Code included)

Asked by 7 years ago
Edited 7 years ago

Hey guys,

So my latest game uses Remote Functions to launch a GUI on the player's screen. This function is then located within a while true loop.

The rest of the script functions as it should, but when it loops around the remote event does not work since it is still broadcasting from the last time. Here is an idea of the code used below.

--Server Script
local raceLight = Instance.new("RemoteFunction")
raceLight.Name = "raceLights"
raceLight.Parent = game.Workspace

while true do
--Stuff about loading the map here
wait(1)
function raceLight.OnServerInvoke()
    print("sending out function")
    return "success"
end
--Stuff about the race and removing the map here
end

^^^This is not the full code, just a snippet where I have the problem!^^^

--Local Script located in StarterPlayerScripts
local message = game.Workspace.raceLight:InvokeServer()
    game.Players.LocalPlayer.PlayerGui.StartingLights.Lights.Visible = true
    wait(2)
    game.Players.LocalPlayer.PlayerGui.StartingLights.Lights.Seq.Disabled = false
print(message)

Is there a way to get the function to stop broadcasting, or should I try another Remote Event style?

0
Why are you setting a new callback to OnServerInvoke every second? This should only be done once, and outside of any loop. You should also take a look at code indentation: http://mrbool.com/importance-of-code-indentation/29079 ScriptGuider 5640 — 7y
0
The code has about 50 other lines. I just removed it to the line that matters (abstraction for the Computer Science OCR student... ????) In reality, it's every 60 seconds the loop comes back around to it. Michael007800 144 — 7y

1 answer

Log in to vote
0
Answered by
Etheroit 178
7 years ago

Place the OnServerInvoke function outside the loop (after creating RemoteFunction object and before line with while true do )

Ad

Answer this question