Hi devs , i actually need to know how can i stop an function. Here is ( not in full ) my script ( i will give more details bellow )
local EventNames = {"SousSol",}
SousSol = function()
if EventCompleted.Value == 1 then
-- script to stop the "SousSol" event
else
-- my script
while true do -- Event restart
local EventName = EventNames[RandomObject:NextInteger(1, #EventNames)]
Events[EventName]()
task.wait(5)
end
So here is my script , i want to stop the event when “EventCompleted.Value == 1” but idk how… can someone can help me?
Using something like return will stop the function from running and carry on with the rest of the script
local EventNames = {"SousSol",}
SousSol = function()
if EventCompleted.Value == 1 then
-- script to stop the "SousSol" event
return
else
-- my script
while true do -- Event restart
local EventName = EventNames[RandomObject:NextInteger(1, #EventNames)]
Events[EventName]()
task.wait(5)
end
end
end
might of formatted your script wrong but hopefully you understand what I mean lol
You can make another remote event where the purpose of the event is to stop the “SousSol” event. When the “SousSol” event fires, create a thread where the function would “kill” the script, resulting in the event no longer being run.
-- Main Script
if EventCompleted.Value == 1 then
StopSousSol:FireServer() -- or client, where ever you are firing it from
end
-- Event Script
SousSol.OnServerEvent:Connect(function()
local dead = false
local thread = nil
thread = StopSousSol.OnServerEvent:Connect(function()
thread:Disconnect()
dead = true
end)
while dead == false do
-- whatever script here
task.wait(5)
end
end)