Im making a main menu in Lua(Roblox Studio) and the start game/play button doesnt work
i tried this code for the play button but the button wasnt responding
local button = script.Parent
local main_menu = script.Parent.Parent.Parent.Parent
local main_menu_frame = script.Parent.Parent.Parent
main_menu.Enabled = true
game.Lighting.Blur.Enabled = true
while true do
if button.MouseButton1Click == true then
game.Lighting.Blur.Enabled = false
main_menu.Enabled = false
main_menu_frame.Active = false
main_menu_frame.Transparency = 1
main_menu_frame.Visible = false
end
task.wait(0.1)
end
Edit: I confused the bool with the event, my bad! Connect a function to the event then run your code.
Change your code to:
local button = script.Parent
local main_menu = script.Parent.Parent.Parent.Parent
local main_menu_frame = script.Parent.Parent.Parent
main_menu.Enabled = true
game.Lighting.Blur.Enabled = true
button.MouseButton1Click:Connect(function()
game.Lighting.Blur.Enabled = false
main_menu.Enabled = false
main_menu_frame.Active = false
main_menu_frame.Transparency = 1
main_menu_frame.Visible = false
task.wait(0.1)
end)
The code you wrote looped while waiting for the button.MouseButton1Click
event to finish. This caused an endless loop of the button triggering and then waiting for the loop to finish.
You do not need a loop to check for the event. Instead, just check if the button MouseButton1Down
event is triggered then run your code, as the task.wait()
function acts as a debounce without the loop.