Repeat wait() problem

Howdy Devs,

I made an in game auto clicker for a simulator that I’m making, but it doesn’t work.
I’m thinking it’s with the repeat wait() but I don’t know.

This is a video on what it’s doing:
link here

I have tried many solutions but every time it doesn’t work. I asked discord servers but they couldn’t find the answer either. There are no errors in the output. And for reference I am using Datastore2.

If you could help at all that would be awesome!
Here’s the code:

local Datastore2 = require(game.ServerScriptService.Modules:WaitForChild("MainModule")) 
local clicksDefaultValue = 0

game.ReplicatedStorage.RemoteEvents.AutoClickEvent.OnServerEvent:Connect(function(plr)	
	local clicksDatastore = Datastore2("clicks", plr)
	local defaultclickMultiplier = plr:WaitForChild("ClickMultiplier").Value
	local leaderstats = plr:WaitForChild("leaderstats")
	local autoClickButton = plr:WaitForChild("PlayerGui").AutoClickGui.Frame.TextButton
	local autoClickBool = plr:WaitForChild("AutoClick")
	
	if autoClickBool.Value == true then
		repeat wait(0.25)
			clicksDatastore:Increment(1 * defaultclickMultiplier, clicksDefaultValue)
		until	autoClickBool.Value == false
	end
end)

Thanks if you can help,
Dash

hmm, wrap the if autoClickBool.Value == true in a Changed event. Yesterday, someone was having an issue with checking how many “Carrots” a player had in their inventory. I told them to wrap it a changed event, and boom. It worked, but I’m not even fully sure why it worked. I think roblox might have updated the way if statements work. They dont check constantly anymore(I think, dont take this as fact). Once the script reads the if statement, it doesn’t read it again unless you make it read it again manually, through something like an event call. After it runs the first time, it’s done(Once again, I think this is how it works now, not 100% sure)

autoClickBool.Changed:Connect(function()
	if autoClickBool == true then
		-- code
	end
end)

It appears you are updating the datastore value, but not the value the player sees. I’ve never used Datastore2, but I’m assuming thats what the increment function is doing.

I have it so that when it increments values to the datastore it also changes it to the leaderstats.

I will definitely try this and see if it works, thanks!

And you are also updating the UI text accordingly? We usually use a serverside int value and detect .Changed in order to update the clientside UI.

Yes, I am updating the UI I have it hooked with a .Changed event in a local script.

let me know if adding the Changed event worked. If it didn’t, then im kinda lost lol. If you did all of the GUI and updating & stuff, and the changed event doesn’t work, then Im clueless. The code looks fine. Its strange.

The Changed event did not work which I was really bummed about. But it’s fine I’m sure i can figure it out.

Ah, dang. Sorry i couldn’t help. good luck too you.

It’s fine, but thanks anyways.

Use an debugger with breakpoints. Witht this, you can watch all steps of what your code is actually doing. I don‘t think that the wait(0.25) is the problem, I have a similar loop that work

Okay, I think I have to fix the Increment since the bool values actually work.