Robbing script doesn't work (Solved)

local Prizes = {

Money1 = 250,

Money2 = 500,

Money3 = 750,

Money4 = 125,

Money5 = 1000,

}

script.Parent.ProximityPrompt.Triggered:Connect(function(Player)

Player.leaderstats.Cash.Value = Player.leaderstats.Money.Value + math.random(Prizes)

script.Parent.ProximityPrompt.Enabled = false

wait(math.random(8,13))

script.Parent.ProximityPrompt.Enabled = true

end)

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

1 Like

Something like this could work:

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 = Player.leaderstats.Money.Value + randomEntry
	script.Parent.ProximityPrompt.Enabled = false
	wait(math.random(8,13))
	script.Parent.ProximityPrompt.Enabled = true
end)
1 Like

Alright Ima try that out, and if it works thanks!

1 Like

It does work but i fixed one mistake u did u used money instead of cash

What you mean? I didnt change that on your script, thats how originally you typed it xD

Oh yeah lol, but do u know how to add a dss onto this script

Sure, what you wanna save on DSS? the amount of money/cash the player got during the session?

the amount of cash that would be lovely thanks!

are you done with the dss? sorry if i disturbed u

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)

Alr it works thanks i appreciate u helping me out

1 Like

No problem :+1:
I made a tiny change in the script (edited my message), maybe you want to use the new one

1 Like

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