Spawn Function Problem

So there was a problem in my game. So I made a flood escape 2 button system but the spawn function won’t function. The methods I do is adding return’s, removing local from local function but it won’t work. Any ideas would be helpful!

local currentbutton = script.OnButton

local function fade(map)
	local interactive = map.Interactives:FindFirstChild("Interactive_"..currentbutton.Value)
	interactive.Transparency = 1
	interactive.CanCollide = false
end

local function appear(map)
	local interactive = map.Interactives:FindFirstChild("Interactive_"..currentbutton.Value)
	interactive.Transparency = 0
	interactive.CanCollide = true
end

local function unanchor(map)
	local interactive = map.Interactives:FindFirstChild("Interactive_"..currentbutton.Value)
	interactive.Anchored = false
	wait(map.Buttons:FindFirstChild("Button_"..currentbutton.Value)._Unanchor.Delay.Value)
	interactive.Transparency = 1
	interactive.CanCollide = false
end

local function check(m)
	
	local cbutton = m.Buttons:FindFirstChild("Button_"..currentbutton.Value)
	
	if cbutton:FindFirstChild("_Fade") then
		
		--spawn(function()
		repeat wait()
		fade(m)
		until fade(m)
		return
		--end)
		
end
	if cbutton:FindFirstChild("_Appear") then
		
		--spawn(function()
			
		repeat wait()
		appear(m)
		until appear(m)
		return
 		--end)
		
   end
	if cbutton:FindFirstChild("_Unanchor") then
		
		spawn(function()
			
		repeat wait()
		unanchor(m)
		until unanchor(m)
		return
		end)
	end
end

I can’t do anything! I tried many times but it won’t work.

did you add an event to fire all those functions?
maybe thats the problem

1 Like

What do you mean? Like a remote function?

It’s a button right? so you use clickdetector?

1 Like

I like using touch, and this script is in the serverscriptservice that is checking maps for buttons and interactives

What i mean is, you need an Event, to fire all those functions, like:

local function whateveryouwant()
-- Do Something
end
local isHit = false
script.Parent.Touched:Connect(function(hit)
     if isHit == false then
         isHit = true
         whateveryouwant()
     end
end)
1 Like

I did that, but I only copied and pasted the part that is nil or false.

K, did you see any error in the output?
if there’s no error you could try adding print() into the functions and events to see if the code got executed

1 Like

Nothing got printed, so I tried putting the print() inside each line in the check() function, but it just printed 6 prints.

You said, there’s 6 prints that got executed, which one got executed? is it in the event? or functions?

1 Like

The prints are in the check() function and the 6 printed were the first ones.

Actually, it didn’t print to the ones with appear() and unanchor()

Are you sure it gets the touch?

Can you post the .Touched Event Codes here? maybe there’s something in the events

1 Like

Yes! Positive. I this script shows the problem. Not the whole script.

I can’t right now though. But the touch function works positive. Just focus on the main parts.

What are you trying to achieve again?

If you don’t know flood escape 2’s buttons, then I will be discussing it. So there are three or more buttons and they have a part. If they click a button, the part activated and the next button turns green. Also the button that just got pressed will turn red.

Then why do you need so many functions, just change the color of the pressed and the other button.