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

why does this short script not work?

Asked by
mehssi 20
9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
btn1 = script.Parent
player = game.Players.LocalPlayer
btn1.MouseButton1Down:connect(function()
game.Lighting.tools.Dribbler:GetChildren().Parent = player.Backpack
end)

please help

3 answers

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

What your issue is line 4. The variables being set to local won't change much. I'm trying to understand what you're trying to accomplish. You're either a: Trying to clone 1 tool into the player's backpack b: Trying to clone a set of tools into the player's backpack Since it's hard to tell which you're going for, I'll offer both solutions.

Solution A:

btn1 = script.Parent
player = game.Players.LocalPlayer

btn1.MouseButton1Down:connect(function()
    game.Lighting.tools.Dribbler:clone().Parent = player.Backpack
end)

Solution B:

btn1 = script.Parent
player = game.Players.LocalPlayer

btn1.MouseButton1Down:connect(function()
    for i,v in pairs(game.Lighting.tools.Dribbler:GetChildren()) do
        v:clone().Parent = player.Backpack
    end
end)

Any questions? Feel free to comment!

0
The variables are on the top of the script and they refer to Objects, it is good practice to make them local. Marios2 360 — 9y
0
@Marios2 True. I heard the script is able to read them faster Shawnyg 4330 — 9y
Ad
Log in to vote
0
Answered by
Ben1925 25
9 years ago

You're trying to set a Table's parent. You can't do that.

In order to set all the Children's Parent, you need to set a Generic For loop, something like this:

for _,v in pairs(game.Lighting.tools.Dribbler:GetChildren()) do
    v:Clone().Parent = player.Backpack
end

Also, I'd recommend using game.ReplicatedStorage instead of game.Lighting. Using game.Lighting as an asset storage is deprecated.

Log in to vote
-1
Answered by
A9X 10
9 years ago

Perhaps set the variables as local variables like so

local btn1 = script.Parent
local player = game.Players.LocalPlayer
btn1.MouseButton1Down:connect(function()
game.Lighting.tools.Dribbler:GetChildren().Parent = player.Backpack
end)

Answer this question