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:

01script.Parent.Touched:Connect(function(Part)
02    local db = false
03    if db == false then
04        db = true
05        if Part:FindFirstChild("Cash") then
06            local Partdecor = Instance.new("ParticleEmitter",script.Parent)
07            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
08            Partdecor.Lifetime=NumberRange.new(1,2)
09            Partdecor.Rate = 2
10            if Part.Parent == nil then
11                wait(1)
12                Partdecor:Destroy()
13            end
14            spawn(function()
15                script.Parent.Parent.Parent.CashToCollect.Value = script.Parent.Parent.Parent.CashToCollect.Value + Part.Cash.Value
View all 22 lines...
  • 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!

01script.Parent.Touched:Connect(function(Part)
02    local db = false
03    if db == false then
04        db = true
05        if Part:FindFirstChild("Cash") then
06            local Partdecor = Instance.new("ParticleEmitter",script.Parent)
07            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
08            Partdecor.Lifetime=NumberRange.new(1,2)
09            Partdecor.Rate = 2
10            if Part.Parent == nil then
11                wait(1)
12                Partdecor:Destroy()
13            end
14            spawn(function()
15                script.Parent.Parent.Parent:FindFirstChild("CashToCollect").Value = script.Parent.Parent.Parent:FindFirstChild("CashToCollect").Value  + Part:FindFirstChild("Cash").Value
View all 22 lines...

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

01script.Parent.Touched:Connect(function(Part) -- part is the part that touched the script's Parent
02    local db = false
03    if db == false then
04        db = true
05        if Part:FindFirstChild("Cash") then
06            local Partdecor = Instance.new("ParticleEmitter") -- don't use second argument of "Instance.new"
07            Partdecor.Texture = "http://www.roblox.com/asset/?id=300899516"
08            Partdecor.Lifetime = NumberRange.new(1,2) or math.random(1,2) -- i don't know what "NumberRange" is
09            Partdecor.Rate = 2
10            Partdecor.Parent = script.Parent
11            if Part.Parent == nil then
12                wait(1)
13                Partdecor:Destroy()
14            end
15            spawn(function()
View all 34 lines...

Hope this helps!

Answer this question