Tool not being equipped on custom backpack

So, the problem here is that the tool cloned get parented to nil for no reason.
This is what happens :

This is the script :

--//== BadlyDev
local Backpack = {}
local context = game:GetService("ContextActionService")
local tween = game:GetService("TweenService")
local event = game.ReplicatedStorage.RemoteEvent
Backpack.__index = Backpack
--// Infos
local NormalColor = Color3.fromRGB(80, 80, 80)
local SelectedColor = Color3.fromRGB(255,255,255)
--//== Constructor
function Backpack.new(plr,tool)
	local self = setmetatable({},Backpack)
	local camera = Instance.new("Camera")
	local ui = script.Backpack:Clone()
	ui.Parent = plr.PlayerGui
	ui.vp.CurrentCamera = camera
	local handle = tool:Clone().Handle
	handle.Parent = ui.vp
	camera.CFrame = CFrame.new(handle.CFrame.p*1.17,handle.Position)*CFrame.Angles(0,0,math.pi/4)
	event:FireClient(plr,ui)
	event.OnServerEvent:Connect(function(player,action)
		if player ~= plr then return end -- Checking if its the actual player.
		if action == 'equip' then
			self:Equip()
		else
			self:Unequip()
		end
	end)
	self.ui = ui
	self.plr = plr
	self.tool = tool:Clone()
	self.tool.Parent = plr:WaitForChild'Backpack'
end
--//== Methods
function Backpack:Equip()
	local char = self.plr.Character or self.plr.CharacterAdded:Wait()
	local hum = char:WaitForChild'Humanoid'
	hum:EquipTool(self.tool)
	print('Equipped.')
end
function Backpack:Unequip()
	local char = self.plr.Character or self.plr.CharacterAdded:Wait()
	local hum = char:WaitForChild'Humanoid'
	hum:UnequipTools()
	print('Unequipped.')
end
function Backpack:Destroy()
	self.ui:Destroy()
end


return Backpack

The script is a ModuleScript that is required by a ServerScript.

β€˜vp’ is a ViewportFrame.
β€˜event’ is a Remote Event in ReplicatedStorage, that fires when the user presses β€˜1’.

Thanks for reading :smiley:

1 Like