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