Failed to change value fast enough

Hello! I’ve had a problem for the last couple of minutes that my “Money” stat isnt updating really quickly, im using a “server” script to give cash to a server leaderboard

Heres the code of the leaderboard:

local plr
local char

local startamount = 100
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("TestMoneyValueNumber7")

game.Players.PlayerAdded:Connect(function(playeradded)

	plr = playeradded
	

	local LeaderstatsFolderInstance = Instance.new("Folder", playeradded)
	LeaderstatsFolderInstance.Name = "leaderstats"

	local MoneyValueInstance = Instance.new("NumberValue", LeaderstatsFolderInstance)
	MoneyValueInstance.Name = "Money"

	local success, fail = pcall(function()

		MoneyValueInstance.Value = ds:GetAsync(plr.UserId) or startamount

	end)

	if success then

		print("Success")

	elseif fail then

		plr:Kick("Failed to load your data, Please jojn again :(")

	end
	
	game.ReplicatedStorage.GiveCashClient.OnServerEvent:Connect(function(plr, Amount)

		MoneyValueInstance.Value += Amount

	end)
	
	game.Players.PlayerRemoving:Connect(function(playerremoved)

		ds:SetAsync(playerremoved.UserId, MoneyValueInstance.Value)

		playerremoved.CharacterRemoving:Connect(function(plrcharacterremoved)



		end)

	end)
	
	plr.CharacterAdded:Connect(function(plrcharacteradded)

		char = plrcharacteradded

	end)

end)

.

And heres the code of the give script

.

game.ReplicatedStorage.GiveCashClient.OnServerEvent:Connect(function(Plr, Amount)
	
	if Plr:FindFirstChild("leaderstats") then
		
		if Plr:FindFirstChild("leaderstats"):FindFirstChild("Money") then
		
		Plr:WaitForChild("leaderstats"):WaitForChild("Money").Value += Amount
			
		else
			
		Plr:Kick("Failed to give cash to player because of missing 'Money', Plr name: "..Plr.Name..", Rejojn and try again ERROR 199")
			
		end	
		
	else
		
		Plr:Kick("Failed to give cash to player because of missing 'leaderstats', Plr name: "..Plr.Name..", Rejojn and try again ERROR 200")
			
	end
	
end)

I have been getting this “bug” and i dont know how to fix it

If needed heres the client that fires the event

local Amount = 500

while wait() do
	
	wait(5)
	
	game.ReplicatedStorage.GiveCashClient:FireServer(Amount)
end

It responds too slow, After its value is 100 then it waits a couple of seconds before setting it to 1100, then again, only adding it if it reaches “1000”
Thanks if you solved the problem :smiley:

You made it every 5 seconds so you need to change it to like 0.5 or 0.1 to make it fast

oh sh- i mean i forgot i made… 2 times the give command… one in the give cash script and one in the leaderstats, and i just realised i dont need to fire the server cause it works just fine as a client

oh i just realised i fucked up and that it wont save as client

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.