Answered by
8 years ago Edited 8 years ago
Storage
Please do not use the Lighting
service to store objects. This method of doing so is years old, and needless to say, deprecated. Look in to using some of ROBLOX's more organized, and practical storage services like ReplicatedStorage, and ServerStorage (I also highly recommend learning the differences between the two, as they both have a very different purpose).
Syntax
First off, you're missing an end
statement near line 5
, where it should close your if statement. This is just going to error immediately with a syntax error, but it should be pretty easy to fix if you pay attention to your Output window
.
Parent
You're not parenting your object once you clone it. Cloned objects will copy every single property of the object you used the method on, except it's parent. This property must be set after you've created the new cloned object, or it's default parent will just remain nil
.
Implementation
Here's your revised code implementing all these corrections:
01 | local function OnClick() |
02 | if Cash.Value > = 20 then |
03 | Cash.Value = Cash.Value - 20 |
04 | Units.Value = Units.Value + 1 |
07 | local Barbarian = game.Lighting.Barbarian:clone() |
10 | Barbarian.Parent = workspace |
15 | script.Parent.MouseButton 1 Click:connect(OnClick) |
If you have any questions about how this works, just let me know. Hope it helped.