I’m not the best at using tables but i tried it, this is a robbing script but idk how to get like each time u rob it that it gives u one of these cash prizes
Something like this. Its a basic example, so you could improve it as you need.
If you already have a PlayerAdded event that is creating the leaderstats folder and the IntValue, you should disable it, cause in this script that is already handled
local DSS = game:GetService("DataStoreService")
local Cash = DSS:GetDataStore("Cash")
local Prizes = {
250,
500,
750,
125,
1000
}
script.Parent.ProximityPrompt.Triggered:Connect(function(Player)
local randomEntry = Prizes[math.random(1, #Prizes)]
Player.leaderstats.Cash.Value += randomEntry
script.Parent.ProximityPrompt.Enabled = false
wait(math.random(8,13))
script.Parent.ProximityPrompt.Enabled = true
end)
game.Players.PlayerAdded:Connect(function(player)
local succ, data = pcall(function()
return Cash:GetAsync(player.UserId)
end)
if succ then
if data then
warn(player,"cash:",data)
-- data is the amount of cash
-- here, create the leaderstats.Cash and insert data into Value
local newFolder = Instance.new("Folder")
newFolder.Name = "leaderstats"
local newInt = Instance.new("IntValue")
newInt.Name = "Cash"
newInt.Value = data
newInt.Parent = newFolder
newFolder.Parent = player
else
-- handle it as you wish, give cash or something
warn("player has no data in DSS, means new player")
local newFolder = Instance.new("Folder")
newFolder.Name = "leaderstats"
local newInt = Instance.new("IntValue")
newInt.Name = "Cash"
newInt.Value = 0
newInt.Parent = newFolder
newFolder.Parent = player
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if player.leaderstats.Cash then
warn("player's current cash:", player.leaderstats.Cash.Value)
local succ, err = pcall(function()
return Cash:SetAsync(player.UserId, player.leaderstats.Cash.Value)
end)
if succ then
warn(player,"cash successfully saved")
else
warn("error", err)
end
end
end)