How can we stop an "event" function?

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?

-tnkss

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

doing a return wont make a prob when events will be chosen? Bcs actually i have a lot of events in the

local EventNames = {"SousSol",}

Actually i need a script who only stop the “SousSol” function and make the randomisation of events still working except the “SousSol”

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)
3 Likes

The return should only stop the SousSol functions, yes

Not 100% sure as I dont have the full script and dont really know how it works
@Dragonfable6000’s solution should also work aswell

I changed " StopSousSol:FireServer()" to “StopSousSol:FireAllClients()” and now it work tnks!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.