I have a GUI gun giver for a gun game and the script keeps interfering with the GUI so it does not appear when a player dies. (Yes, ResetonSpawn is enabled.)

Here is my code:

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

function chooseClass(class)
	for i, v in pairs(backpack:GetChildren()) do v:remove() end
	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.Title.Visible = false
end

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

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

2 comments

0

Are you reciving any errors in the studio output or developer console?

0

Change v:remove() into v:Destroy() and change v.MouseButton1Up:connect to v.MouseButton1Up:Connect