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

Cash is not a valid member of Part "Part"?

Asked by 4 years ago
Edited 4 years ago

Hey, i am having an issue with the new tycoon i am making. But there is a cash value in the part.

Code:

script.Parent.Touched:Connect(function(Part)
    local db = false
    if db == false then
        db = true
        if Part:FindFirstChild("Cash") then
            local Partdecor = Instance.new("ParticleEmitter",script.Parent)
            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
            Partdecor.Lifetime=NumberRange.new(1,2)
            Partdecor.Rate = 2
            if Part.Parent == nil then
                wait(1)
                Partdecor:Destroy()
            end
            spawn(function()
                script.Parent.Parent.Parent.CashToCollect.Value = script.Parent.Parent.Parent.CashToCollect.Value + Part.Cash.Value
                Part:Destroy()
            end)    
        end
        wait(.2)
        db = false
    end
end)
  • Error : Cash is not a valid member of Part "Part"
0
dont forget to accept my answer if it worked! ProvingTrottle 27 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Fixed!

script.Parent.Touched:Connect(function(Part)
    local db = false
    if db == false then
        db = true
        if Part:FindFirstChild("Cash") then
            local Partdecor = Instance.new("ParticleEmitter",script.Parent)
            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
            Partdecor.Lifetime=NumberRange.new(1,2)
            Partdecor.Rate = 2
            if Part.Parent == nil then
                wait(1)
                Partdecor:Destroy()
            end
            spawn(function()
                script.Parent.Parent.Parent:FindFirstChild("CashToCollect").Value = script.Parent.Parent.Parent:FindFirstChild("CashToCollect").Value  + Part:FindFirstChild("Cash").Value
                Part:Destroy()
            end)    
        end
        wait(.2)
        db = false
    end
end)

Basically, I just changed this to :FindFirstChild!

EDIT: Changed script.Parent.Parent.Parent.CashToCollect.Value to script.Parent.Parent.Parent:FindFirstChild("CashToCollect").Value

0
Now i have the error: Workspace.Newer Tycoon.Tycoons.Red Team.Essentials.Collector.Script:17: attempt to index nil with 'Value'  NillaTheCat12345 14 — 4y
0
okie ProvingTrottle 27 — 4y
0
Fixed! ProvingTrottle 27 — 4y
0
noice! IAmRandomPlayer8263 15 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try doing this code (FindFirstChild might not work):

script.Parent.Touched:Connect(function(Part) -- part is the part that touched the script's Parent
    local db = false
    if db == false then
        db = true
        if Part:FindFirstChild("Cash") then
            local Partdecor = Instance.new("ParticleEmitter") -- don't use second argument of "Instance.new"
            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
            Partdecor.Lifetime = NumberRange.new(1,2) or math.random(1,2) -- i don't know what "NumberRange" is
            Partdecor.Rate = 2
            Partdecor.Parent = script.Parent
            if Part.Parent == nil then
                wait(1)
                Partdecor:Destroy()
            end
            spawn(function()
                local cash = Part:FindFirstChild("Cash") or Part:FindFirstChild("Cash", true)
                if cash == nil then
                    cash = Part:WaitForChild("Cash",10)
                    if cash == nil then -- double check
                        warn("Cash is nil, returning function...")
                        return
                    end

                    script.Parent.Parent.Parent.CashToCollect.Value += cash.Value -- the same thing as the long add code
                end

                script.Parent.Parent.Parent.CashToCollect.Value += cash.Value
                Part:Destroy()
            end)
        end
        wait(.2)
        db = false
    end
end)

Hope this helps!

Answer this question