I got this Datastore2 script from AlvinBlox Youtube Video.

local DataStore2 = require(1936396537)

  

local defaultValue = 2000

  

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

local cashDataStore = DataStore2("cash",plr)

local Stats = Instance.new("Folder",plr)

Stats.Name = "Stats"

local cash = Instance.new("IntValue",Stats)

cash.Name = "Cash"

local function cashUpdate(updatedValue)

cash.Value = cashDataStore:Get(updatedValue)

end

cashUpdate(defaultValue)

cashDataStore:OnUpdate(cashUpdate)

end)

  

game.Workspace:WaitForChild("Part").ClickDetector.MouseClick:Connect(function(player)

local cashDataStore = DataStore2("cash",player)

cashDataStore:Increment(400,defaultValue)

  

end)

and I want to change this part that give the 5 cash every 10 seconds. How do I change it?

game.Workspace:WaitForChild("Part").ClickDetector.MouseClick:Connect(function(player)
        
        local cashDataStore = DataStore2("cash",player)
        
        cashDataStore:Increment(400,defaultValue)
        
          
        
        end)

3 comments

0

The code you posted shows that their cash increases every time they click the ClickDetector, not on a timer

0

I mean I want to change that part of the script into timer.

0

Try removing the click detector and replace with a WhileLoop linked directly to each player. Then shove in a wait to create the time between money gain.