so, ya i dont know why this isnt working when clicked on a gui then it clones a zombie from the lighting to the workspace heres the code
function onClick() if Cash.Value >= 20 then Cash.Value = Cash.Value - 20 Units.Value = Units.Value + 1 local Barbarian = game.Lighting.Barbarian:clone() end script.Parent.MouseButton1Click:connect(onClick)
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).
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
.
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
.
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 -- Use a storage service I mentioned above instead of lighting. local Barbarian = game.Lighting.Barbarian:clone() -- Now parenting the cloned object to workspace. Barbarian.Parent = workspace end -- Don't forget to end your scopes end script.Parent.MouseButton1Click:connect(OnClick)
If you have any questions about how this works, just let me know. Hope it helped.
The problem is that you have not end
ed your if statement, like this:
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)
You should also consider using ReplicatedStorage rather than Lighting for storage.
Edit: You need to set the parent of the clone. Updated the code.