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

What did I do wrong? I need help fixing a robbing bank code. [Just a little fix]

Asked by 5 years ago

I don't know why CashPiles is underlined in red

local moneyData = script.Parent:GetChildren()

if CashPiles.Name == "Stack" then
    cashpiles: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:FindFirstChild('Cash').Transparency == 0 then
                    plr.Wallet.Value = 5000
                    local parts = cashpiles: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 

2 answers

Log in to vote
1
Answered by
Zeluxis 100
5 years ago

In Lua, or most coding programs, you absolutely need to understand that capital letters mean everything.

A perfect example of this would be a part of your script that states:

"Touched:connect(function(hit)"

This is wrong. The correct line of code would be:

"Touched:Connect(function(hit)"

Although it works the same way, you may be thinking, whats the difference? Well, ROBLOX has deprecated "connect" as it does not coincide with the capital letters on other things within the Lua program.

You must make sure every line of your code, especially when outlining something such as CashPiles, that you do it exactly.

tl;dr, it's not working because you defined "CashPiles" but then used "cashpiles" later on in the code. They both need to be "CashPiles".

Ad
Log in to vote
0
Answered by
EzioEE -2
5 years ago

you didn't make cashpiles:FindFirstChild("Cash") a capital c and P

    if CashPiles.Name == "Stack" then
        cashpiles: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:FindFirstChild('Cash').Transparency == 0 then
                        plr.Wallet.Value = 5000
                        local parts = CashPiles: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

Answer this question