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

How come my clone script doesnt' work?

Asked by
Yeevivor4 155
9 years ago

Hi, what I'm trying to do here is clone a weapon called "M16" to a players backpack. To do this, I try to cilck a Part and then it will clone a Weapon to a players backpack.

     gunmodel = script.Parent
     players = game.Players.LocalPlayer
    function onClicked()
        for i = 1, #players do
        if gunmodel ~= nil then
        gun = game.Lighting.Weapons.M16:clone()
        gun.Parent = players.Backpack
        wait(.1)
        script.Parent:Destroy()
        end
        end
        end
    script.Parent.ClickDetector.MouseClick:connect(onClicked)
0
Oh yeah, just another tip.. you don't need to use lighting anymore. You can use ServerStorage. It's a better place to store it. lomo0987 250 — 9y
0
There is a problem. It says that "player" is a nil value Yeevivor4 155 — 9y
0
is this a script inside a brick or a player? lomo0987 250 — 9y
0
It is inside a brick named "Part" Yeevivor4 155 — 9y
View all comments (7 more)
0
So, do you want to give everyone the gun when the brick is clicked? or just the player who clicked it? lomo0987 250 — 9y
0
Very sorry for the late reply, I'm trying to give it to the player who clicked it, not everyone. Yeevivor4 155 — 9y
0
there, i fixed it for you. it should work fine now lomo0987 250 — 9y
0
Okay, I'll check it out and give you a green check mark Yeevivor4 155 — 9y
0
if it doesn't work, just tell me where it breaks. I might have got the player situation wrong. lomo0987 250 — 9y
0
Wow, it works, thanks for sticking with me to the end. Yeevivor4 155 — 9y
0
Okay, I'll check it out and give you a green check mark Yeevivor4 155 — 9y

1 answer

Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
9 years ago
Gun = game.Lighting.Weapons:FindFirstChild("M16") -- You first need to locate what you want to clone outside of the function.
function onClicked(player)
    ClonedGun = Gun:clone() -- clone what you want and give it another name.
    ClonedGun.Parent = player.Backpack -- put what you cloned inside the backpack of the player
    wait(.1)
    script.Parent:Destroy() -- delete this if you want anyone who clicks on the brick to get the gun.
    end
    end
    end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Ad

Answer this question