I want to make this button that gives you a tool (directly inside the button inside) when you click on it. I’ve got this script, but it doesn’t work. How do I make it work? I got two errors, but they don’t relate to the tool giving script.
player = script.Parent.Parent.Parent
backpack = player.Backpack
function onClick()
for i, v in pairs(class:GetChildren()) do
if v:IsA("Tool") then
v:clone().Parent = backpack
elseif v:IsA("HopperBin") then
v:clone().Parent = backpack
end
end
end
local button = script.Parent
player = script.Parent.Parent.Parent
backpack = player.Backpack
function button.MouseButton1Down:Connect(OnClick)
for i, v in pairs(class:GetChildren()) do
if v:IsA("Tool") then
v:clone().Parent = backpack
elseif v:IsA("HopperBin") then
v:clone().Parent = backpack
end
end
end
I have no idea how you translated it to that, but no. Like this:
local button = script.Parent
local player = script.Parent.Parent.Parent
local backpack = player.Backpack
function onClick()
for i, v in pairs(class:GetChildren()) do
if v:IsA("Tool") then
v:clone().Parent = backpack
elseif v:IsA("HopperBin") then
v:clone().Parent = backpack
end
end
end
button.MouseButton1Down:Connect(OnClick)
Clone() function has a capital “C”. Copy and paste this code here:
local button = script.Parent
local player = script.Parent.Parent.Parent
local backpack = player.Backpack
function onClick()
for i, v in pairs(class:GetChildren()) do
if v:IsA("Tool") then
v:Clone().Parent = backpack
elseif v:IsA("HopperBin") then
v:Clone().Parent = backpack
end
end
end
button.MouseButton1Down:Connect(OnClick)