PLEASE NOTE THAT THIS PROJECT IS JUST FOR TESTING; I WILL RE WRITE THE CODE AND RE BUILD EVERYTHING TO MAKE IT ORGANISED WHEN THE SYSTEM WORKS.
So i’m making a main menu script where the player can go from the main menu to the intermission screen. Everything was working fine until i added a physical ‘back’ button that worked perfectly but somehow only made a function run once. The function is there to take the player out of the main menu camera loop and put his camera CFrame on the intermission screen by simply clicking a ‘play’ button.
The script below shows you a local script with the loop, and the remote event being detected (when the player goes ‘back’) causing the function to run.
Here’s the script:
local deb = true
local function MainMenuCamera()
while deb == true do
script.Parent.MouseButton1Click:Connect(function()
deb = false
print("Yes")
Animation1:Cancel()
Animation3:Cancel()
camera.CFrame = workspace.CameraE1.CFrame
script.Parent.Parent.Parent.Parent.IntermissionButtons.Enabled = true
end)
camera.CFrame = Camera1.CFrame
Animation1:Play()
Animation1.Completed:Wait()
camera.CFrame = Camera5.CFrame
Animation3:Play()
Animation3.Completed:Wait()
print("Yes2")
end
end
MainMenuCamera()
game.ReplicatedStorage.BackArrow.OnClientEvent:Connect(function()
deb = true
MainMenuCamera()
print("Bruh")
end)
I think you use deb for a debounce. However, you never set deb to true at the end. It says while deb == true do, but if deb is never true it won’t run. It only runs once because deb is only true once.
You didn’t set debounce to true at the end which means it will only run once, I can only see that you set debounce to true on the local script but that won’t work. Just set the debounce to true when the function has finished so that the debounce can allow the function to run again.
you only called the function once set it in a while loop
local deb = true
local function MainMenuCamera()
while deb == true do
script.Parent.MouseButton1Click:Connect(function()
deb = false
print("Yes")
Animation1:Cancel()
Animation3:Cancel()
camera.CFrame = workspace.CameraE1.CFrame
script.Parent.Parent.Parent.Parent.IntermissionButtons.Enabled = true
end)
camera.CFrame = Camera1.CFrame
Animation1:Play()
Animation1.Completed:Wait()
camera.CFrame = Camera5.CFrame
Animation3:Play()
Animation3.Completed:Wait()
print("Yes2")
end
end
while wait(.5) do
MainMenuCamera()
end
The problem isn’t the ‘MainMenuCamera()’ not running, its the: script.Parent.MouseButton1Click:Connect(function()
not running.
I don’t really see how setting a while loop in the OnClientEvent function would fix the problem. In addition the ‘MainMenuCamera()’ already has a while loop in it so i don’t see why i should add wrap another while loop on it.
I may have misunderstood what you were trying to say, if so let me know!
I used print to find out what was running and what wasn’t. For some reason even if i use that method, the script.Parent.MouseButton1Click:Connect(function() just wont fire at all (It doesn’t print ‘Yes’. Everything else works, just not this simple function…
Iv’e also tried re-ordering everything in the function such as putting deb = false at the bottom of the function and in the middle, but that just messes up the system completely.
Going off topic, but you are creating new mousebutton1click event everytime it loops, which could go on a long time. Which is generally in my mind, is a bad practice.
Can’t you just check if the player is not in the menu? Ex. Add a function outside the loop (I suggest before the loop, unless you want to use coroutines.)
local OnMenu = false
ButtonToCloseMenu.MouseButton1Click:Conenct(function()
OnMenu = false
end)
OtherButtonToOpenMenu.MouseButton1Click:Connect(function()
OnMenu = true
end)
while OnMenu == true dO
--stuff
end
local deb = true
local function MainMenuCamera()
while deb do
wait(1)
deb = false
print("Yes")
Animation1:Cancel()
Animation3:Cancel()
camera.CFrame = workspace.CameraE1.CFrame
script.Parent.Parent.Parent.Parent.IntermissionButtons.Enabled = true
camera.CFrame = Camera1.CFrame
Animation1:Play()
Animation1.Completed:Wait()
camera.CFrame = Camera5.CFrame
Animation3:Play()
Animation3.Completed:Wait()
print("Yes2")
end
end
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.BackArrow.OnClientEvent:Connect(function()
deb = true
MainMenuCamera()
print("Bruh")
end)
end)
I need to know where you fired your event from the server it’s just maybe one of the problems