Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why does this short script not work?

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

please help

3 answers

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!

2 comments

0

The variables are on the top of the script and they refer to Objects, it is good practice to make them local.

0

@Marios2 True. I heard the script is able to read them faster

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.

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.