I am making an FPS game where you select your three weapons from three different lists at the start, then use them to fight other players. For some reason, all the buttons currently in the GUI work, but if I copy them, they cease to function. There is no code in each button, only a script that detects what button is pressed and what tool to give.

player = script.Parent.Parent.Parent
backpack = player.Backpack

function chooseClass(class)
	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
	
	script.Parent.Main.Visible = false
	script.Parent.Main.Title.Visible = false
end

function onHumanoidDied(humanoid, player)
	script.Parent.Main.Visible = true
	script.Parent.Main.Title.Visible = true
	end

for i, v in pairs(script.Parent.Main:GetChildren()) do
	v.MouseButton1Up:connect(function () chooseClass(v) end)
end

Does anybody know why this would happen? I have tried everything from making my own original button, but that didn't work. I copied buttons before, and it worked, but now it doesn't for ANY tool.

In case this helps, the way it is structured is it has the main GUI > Script (see above), Main. Main > Button > Tool

This script is an essential part of my game, and I am very new to coding, but have learned bits and pieces here and there.

Edit: The script is not a local script.

1 comment

0

is it a local script? if it is then that's why tools don't work, make it a server script