Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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".

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

This discussion is preserved as it was. New answers, comments, and votes are closed.