Ok, I am back again with Datastore2.
So now, I want to add a plus value when someone wins. But I can only do it inside of the function. I wanna do it outside. Here is the code.
local DataStore2 = require(1936396537) -- asset id of the module
local defaultValue = 0 -- default amount
game.Players.PlayerAdded:Connect(function(player)
local pointsDataStore = DataStore2("points",player)
local leaderstats = Instance.new("Folder") -- create leaderstats
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local points = Instance.new("IntValue") -- create your value
points.Name = "Wins"
points.Parent = leaderstats
local function pointsUpdate(updatedValue) -- getting updated value
points.Value = pointsDataStore:Get(updatedValue)
end
pointsUpdate(defaultValue)
pointsDataStore:OnUpdate(pointsUpdate)
wait(60)
pointsDataStore:Increment(1,defaultValue) -- incrementing the value by 5 after waiting 60 seconds; make sure the defaultValue is always the second argument
end)
Should I just use regular datastores for this instance?