Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

One of my variables isn't valid how can I fix this? Robbable Bank

Asked by 5 years ago

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)
0
ur suppose to make ur bank unrobbable though xddddddddddddddddddddddddddddddd greatneil80 2647 — 5y
0
true dahnari 7 — 5y
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. sleazel 1287 — 5y
0
did you follow AlvinBlox's tutorial NSMascot 113 — 5y

Answer this question