Genuienly inexplicable bug, can't describe in title

im trying to make a main menu spawn/play button that once clicked it spawns you and the main menu camera fx stops but the camera fx loop seems to be bugged badly. even after removing the extra code from the while loop and the clicked function this simple code just refuses to work the way it should

local debounce = false
local respawned = false

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if debounce == false then
		respawned = true
		print("respawned!")
	end
end)

while respawned ~= true do
	print(respawned)
	wait()
end
print("done")

expected result
false
false
respawned!
done

actual result

image

AFTER FURTHER TESTING
THIS BREAKS LOGIC EVEN MORE

local debounce = false
local respawned = false

script.Parent.TextButton.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		respawned = true
		while true do
			print("2 "..tostring(respawned))
			wait()
		end
	end
end)

while respawned ~= true do
	print("1 "..tostring(respawned))
	wait()
end

EXPECTED RESULT
1 false
1 false
2 true
1 true
2 true
1 true

ACTUAL RESULT

image

AFTER FURTHER TESTING
THEY MADE ME INSTALL EVIL ROBLOX STUDIO OR SOMETHING

local TEST = false

script.Parent.TextButton.MouseButton1Click:Connect(function()
	TEST = true
end)

while TEST == false do
	print(TEST)
	wait()
end

print("DONE")

how does the loop end yet continue at the same time

image

is your local script in a ScreenGui?
if yes turn off ResetOnSpawn on your ScreenGui

yes, it’s in a screen gui
yes ResetOnSpawn is off

also, I disabled the respawn function of the gui just to test the logic of this while loop so that wouldn’t even be a problem

try adding “break” in the while loop once the targeted value is reached

i found the solution
the script ran twice, once in replicatedfirst and once when the gui was actually in the players playergui.

oh :sob: well have a great day 30charlimittttt

1 Like

Why use a while loop like this. Also that wait() is a bit fast try task.wait(1) or more.
You could make this a .Changed:Connect off a bool or do the respawn in the MouseButton1Click chunk.

the while loop is because some effects are applied to the camera while you aren’t spawned yet

the wait() was for testing

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