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()

01if CashPiles.Name == "Stack" then
02    cashpiles:FindFirstChild('Cash').Touched:connect(function(hit)
03        if hit.Parent then
04            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
05            local hum = hit.Parent:FindFirstChild("Humanoid")
06            if hum then
07                if cashpiles:FindFirstChild('Cash').Transparency == 0 then
08                    plr.Wallet.Value = 5000
09                    local parts = cashpiles:GetChildren()
10                    for p = 1, #parts do
11                        if parts[p]:IsA('Part') then
12                            if parts[p]:FindFirstChild('Texture') then
13                                parts[p]:FindFirstChild('Texture').Transparency = 1
14                            end
15                            parts[p].Transparency = 1
View all 23 lines...

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

01if CashPiles.Name == "Stack" then
02    cashpiles:FindFirstChild('Cash').Touched:connect(function(hit)
03        if hit.Parent then
04            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
05            local hum = hit.Parent:FindFirstChild("Humanoid")
06            if hum then
07                if CashPiles:FindFirstChild('Cash').Transparency == 0 then
08                    plr.Wallet.Value = 5000
09                    local parts = CashPiles:GetChildren()
10                    for p = 1, #parts do
11                        if parts[p]:IsA('Part') then
12                            if parts[p]:FindFirstChild('Texture') then
13                            parts[p]:FindFirstChild('Texture').Transparency = 1
14                        end
15                            parts[p].Transparency = 1
View all 23 lines...

Answer this question