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)
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.
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.
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