01 | local localmoney = script.Parent.Parent:FindFirstChild( 'money' ) |
02 | function touch(part) |
03 |
04 | if part.Name = = ( "Acube" ) then |
05 | part:Destroy() |
06 | localmoney.Value = localmoney.Value + 5 |
07 |
08 | end |
09 | end |
10 |
11 | script.Parent.Touched:connect(touch) |
Let me help you with this. In my opinion, you should increment the Localmoney first before destroying because the script will be destroyed as well!
Here is the script:
01 | local localmoney = script.Parent.Parent:FindFirstChild( 'money' ) |
02 | function touch(part) |
03 |
04 | if part.Name = = ( "Acube" ) then |
05 | localmoney.Value = localmoney.Value + 5 |
06 | part:Destroy() |
07 | end |
08 | end |
09 |
10 | script.Parent.Touched:connect(touch) |
Any questions? Leave a comment below! Thanks and I hope this will help you!