[SOLVED] When i click the lags happens

Hello guys i just found another issue this time the click add system is working, but the lag happens everytime i click…

So i decided to make a button but if you click the button 5 times a mysterious button appears…

Script:

local Clicks = script.Clicks
script.Parent.Text = "You clicked "..Clicks.Value.." times"

script.Parent.MouseButton1Click:Connect(function()
	Clicks.Value = Clicks.Value + 1
	repeat 
		script.Parent.Text = "You clicked "..Clicks.Value.." times"
	until Clicks.Value == 5 -- ISSUE ! (Line 8)
	if Clicks.Value == 5 then
		task.wait(1)
		script.Parent.Parent.OpenTheFrame.Visible = true
		script.Parent.Visible = false
	else
		script.Parent.Visible = true
	end
end)

It’s a LocalScript…

Bug of the issue:

Video:

Care until 56 seconds, please…

So yeah any help is appreciated…

This is just a minor bug and i’m gonna script the button that doesn’t work…

in repeat functions, its good to have a task.wait() so the script doesnt lag out.
Its why people usually to while task.wait() do instead of while true do

Do this instead:

repeat
	task.wait()
until Clicks.Value == 5 -- ISSUE ! (Line 8)

Printing a lot also causes lag, so i would recommend removing the printing, considering no ones going to see it, plus it would clog the output with useless information.

1 Like

Alright, done…

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.TeleportOtherGamesFrame.Visible == false then
		script.Parent.TeleportOtherGamesFrame.Visible = true
	else
		script.Parent.TeleportOtherGamesFrame.Visible = false
	end
end)

True, but i don’t know why this still lags out and also i used task.wait(1) after if the click count is more or equal to 5…

while task.wait() do And while true do are literally almost the same so i used a second of delay so the button can be “Deployed”.

Thanks, i didn’t know there was no lag if we added the task.wait() thing…

Other people cannot help me anymore because it got solutioned…