Hey, i am having an issue with the new tycoon i am making. But there is a cash value in the part.
Code:
01 | script.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 |
Fixed!
01 | script.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 |
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):
01 | script.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 () |
Hope this helps!