Weapon Selection Screen Buttons Not Working

Hello! I am trying to make a simple weapon selection system where the player is prompted to pick a weapon when they first join the game or die and respawn.

For whatever reason, new buttons don’t work. Adding new or copy/pasting existing buttons results in nothing happening. (The bottom 2 buttons in the video are the new ones that aren’t doing anything)

I have already looked to see if anybody has had a similar issue, but I can’t find something like this.

here is what the explorer looks like:
image

and here is the script:

local player = script.Parent.Parent.Parent
local backpack = player.Backpack
local serverStorage = game:GetService("ServerStorage")

function chooseClass(class)
	local v = serverStorage:WaitForChild(class.Name)
		v:clone().Parent = backpack
		script.Parent.Main.C4:Clone().Parent = backpack
		script.Parent.Main["[WIP] Grenade"]:Clone().Parent = backpack
		script.Parent.Main["Bear Trap"]:Clone().Parent = backpack
		script.Parent.Main.Visible = false
	end



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

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

A few things,

:connect is deprecated, instead use :Connect

Second,

Check in the loop to make sure v is a tool (that is if you only want the tools, and there is no tool in ServerStorage that has the name that the buttons have):

for i, v in pairs(script.Parent.Main:GetChildren()) do
    if not v:IsA("Tool") then continue end
	v.MouseButton1Up:connect(function () chooseClass(v) end)
end

This alone might fix your issue, since you are using wait for child, you might be experiencing a infinite yield since there was no tool with the name of the gui button in ServerStorage

1 Like

I have tried both things that you have mentioned. Unfortunately, this has an adverse affect on the system, this causes none of the buttons to work at all.

That’s what I was asking, can I see your ServerStorage

What if you try to replace

With:

script.Parent.Main.ChildAdded:Connect(function()

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

end)

It has the same effect, none of the buttons work.