I Have a money system on my game that gives each player a certain amount of money every 10 seconds. The code for that localscript is below. BRB is the Instance with the money value.
while true do
wait(10)
game.Players.LocalPlayer.BRB.Value = game.Players.LocalPlayer.BRB.Value + 10
end
I recently made a Datastore script and placed it in serverscriptservice. This script is supposed to save every player's money whenever they leave and join the game so no money is lost. For some reason the script is not saving anything at all. I cannot seem to figure out what I did wrong. Code for that script below:
local DataStore = game:GetService("DataStoreService")
local Points = DataStore:GetDataStore("PointSave")
game.Players.PlayerAdded:connect(function(p)
local BankRollBux = Instance.new("IntValue")
BankRollBux.Parent = p
BankRollBux.Name = "BRB"
BankRollBux.Value = Points:GetAsync(p.UserId) or 0
Points:SetAsync(p.UserId, BankRollBux.Value)
BankRollBux.Changed:connect(function()
print("Saving")
Points:SetAsync(p.UserId, BankRollBux.Value)
print("Saved")
end)
end)
game.Players.PlayerRemoving:connect(function(p)
Points:SetAsync(p.UserId, p.BRB.Value)
end)

1 comment
Thank you, just did that and now it works perfectly. Appreciated.