✓ Accepted answer
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:
local function OnClick()
if Cash.Value >= 20 then
Cash.Value = Cash.Value - 20
Units.Value = Units.Value + 1
local Barbarian = game.Lighting.Barbarian:clone()
Barbarian.Parent = workspace
end
end
script.Parent.MouseButton1Click:connect(OnClick)
If you have any questions about how this works, just let me know. Hope it helped.
1 comment
it didint work with that and it wasent any errors