Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Cloning from lighting to workspace?

Asked by
DevingDev 346 Moderation Voter
8 years ago

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)

2 answers

Log in to vote
2
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:

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.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

The problem is that you have not ended 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.

0
it didint work with that and it wasent any errors DevingDev 346 — 8y

Answer this question