I made myself a custom Gui backpack, and removed the core backpack. My issue is that the tools only work when the player spawns in the game. After a death, the tool glitches, and after another death, the tool just doesn't equip. I've included an unequip on death and even cloning the tools from replicated storage to see if would fix my issue, but it did not. My code for all of those things will be posted here.
Gui Equip tool:
_G.weaponName = 'Nothing'
button.MouseButton1Down:Connect(function()
local myWeapon = weaps:FindFirstChild(_G.weaponName)
print(_G.weaponName)
player.Character.Humanoid:EquipTool(myWeapon)
local weaponBackpack = script.Parent.Parent.Parent.ScrollingFrame:GetChildren()
for i = 1, #weaponBackpack do
if weaponBackpack[i].BorderSizePixel ~= 0 then
weaponBackpack[i].BorderSizePixel = 0
end
end
end)
Unequip on death:
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 0 then
humanoid:UnequipTools()
for _,v in pairs(backpack:GetChildren()) do
local tool = v
if v.ClassName == 'Tool' then
v:Destroy()
end
end
end
end)
Clone tools into backpack: <-Happens regardless if I have this script or not
player.CharacterAdded:Connect(function(character)
print(character.Name..' has spawned in!')
local newTools = toolReplicates:GetChildren()
for _,v in pairs(newTools) do
local tool = v:Clone()
local tool2 = tool:Clone()
tool.Parent = backpack
tool2.Parent = startgear
end
end)
