This script is for when someone robs the bank and picks up cash. Is there any errors in this because it wouldn't add money to the player's wallet.

Cash Script for Bank System

local cashpiles = script.Parent:GetChildren()

for c = 1, #cashpiles do
	if cashpiles[c].Name == "1K_Cash" then
		cashpiles[c]:FindFirstChild('Cash').Touched:connect(function(hit)
			if hit.Parent then
				local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
				local hum = hit.Parent:FindFirstChild("Humanoid")
				if hum then
					if cashpiles[c]:FindFirstChild('Cash').Transparency == 0 then
						plr.Wallet.Value = plr.Wallet.Value + 5000
						local parts = cashpiles[c]:GetChildren()
						for p = 1, #parts do
							if parts[p]:IsA('Part') then
								if parts[p]:FindFirstChild('Texture') then
									parts[p]:FindFirstChild('Texture').Transparency = 1
								end
								parts[p].Transparency = 1
								parts[p].CanCollide = false
							end
						end
					end
				end
			end
		end)
	end 
end 

This next script is for the money system that I should go along with the 1st script. Is there anything wrong in this script?

function addStats(p, playerStorage)
	
	local key = "player-id"..p.userId
	
	local savedValue = playerStorage:GetAsync(key)
	local ls = p:WaitForChild("leaderspats")
	repeat wait() until ls
	
	if savedValue then
		ls.Money.Value = savedValue
		p.PlayerGui["PaydayGui"].WalletAmount.Text = "Wallet: "..tostring(savedValue)	
	else
		local valuesToSave = ls.Money.Value
		print(valuesToSave.."VALUES")
		p.PlayerGui["PaydayGui"].WalletAmount.Text = "Wallet: "..tostring(valuesToSave)	
		playerStorage:SetAsync(key, valuesToSave)
	end
	end

game.Players.PlayerAdded:connect(function(p)
	print('GETTING')
	local playerStorage = game:GetService("DataStoreService"):GetDataStore("Money")
	print('RECEIVED')
	addStats(p, playerStorage)
	print('ADDED')
end)

game.Players.PlayerRemoving:connect(function(p)
	local playerStorage = game:GetService("DataStoreService"):GetDataStore("Money")
	local key = "player-id"..p.userId	
	
	local ls = p:WaitForChild("leaderspats")	
	
	local valuesToSave = ls.Money.Value
	playerStorage:SetAsync(key, valuesToSave)
end)

4 comments

0

ur suppose to make ur bank unrobbable though xddddddddddddddddddddddddddddddd

0

true

0

You have misspelled leaderstats (leaderspats). Also why not simply Destroy() cash after picking up? The script will run until end, even when parent is destroyed.

0

did you follow AlvinBlox's tutorial