Weapon Disappearing Problem

I made an inventory system where you click the weapon you want equipped and it removes the old weapon, clones, parents, and welds the new weapon to your characters right hand. But the problem is when a weapon is equipped it deletes after it pops up, so you have to equip every weapon twice in order for them to work which is pretty annoying.

This is a video of the weapon not popping up to first time its equipped:

This is a video of the workspace when the weapon is equipped:

The weapon is equipped when “EquippedWeapon” is replaced with “LongswordBase”, then as you can see the weapon deletes itself.

Script inside equip button:

script.Parent.MouseButton1Click:Connect(function()
	local plr = game:GetService("Players").LocalPlayer
	local plrInventory = plr.Inventory
	local frame = script.Parent.Parent
	local RepStor = game:GetService("ReplicatedStorage")
	
	for _,weapon in pairs(plrInventory:GetChildren()) do
		if weapon.Name == frame.Name and weapon.Identifier.Value == frame.Identifier.Value then
			
			RepStor.RemoteEvents.WeaponWelds:FireServer(weapon)
			
		end
	end
	
end)

So when the equip button is pressed a remote event fires and the weapon parameter is sent to the a server script.

Server Script:

RS.RemoteEvents.WeaponWelds.OnServerEvent:Connect(function(plr, weapon)
	
	char = plr.Character
	local hand = char.RightHand
	local sheathed = plr.Character.Values.Sheathed.Value
	local swordtype = weapon:FindFirstChildOfClass("StringValue")
	print(swordtype)
	print(weapon)
	
	for _, oldweapon in pairs(hand:GetChildren()) do
		if oldweapon:FindFirstChild("Handle") then
			oldweapon:Destroy()
		end
	end
			
	local equipped = weapon:Clone()
	equipped.Parent = hand
	
-------------------------------------WELD SENDER-------------------------------------------
	if sheathed == true then
		
		print("we not there yet")
		
	else
		
		if swordtype.Name == "Longsword" then
		
			LongswordToHandWeld(plr, weapon)
		end
		
	end
-------------------------------------------------------------------------------------------	
	
	
end)

--// WELD FUNCTIONS \\--

function LongswordToHandWeld(plr, weapon)
	char = plr.Character
	
	local SwordToHand = Instance.new("Weld")
		SwordToHand.Name = "SwordToHand"
		SwordToHand.Parent = weapon
		SwordToHand.Part0 = weapon.Handle
		SwordToHand.C0 = CFrame.new(0,-.38,0) * CFrame.Angles(0,0,0)
		SwordToHand.Part1 = char.RightHand
		
		char.Animate.idle.Animation1.AnimationId = "rbxassetid://5008254428"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://5008311723"
		plr.Character.Dasher.Dash.AnimationId = "rbxassetid://5008809963"
end 

How do I stop the new weapon from deleting when its added to the players hand?

In your code on the server your not actually adding the weld to equipped variable because later on you pass the weapon argument to welding function and not the actual clone, hence why it only works the second time, in addition you should weld the weapon before adding to the character so try doing this:

RS.RemoteEvents.WeaponWelds.OnServerEvent:Connect(function(plr, weapon)
	
	char = plr.Character
	local hand = char.RightHand
	local sheathed = plr.Character.Values.Sheathed.Value
	local swordtype = weapon:FindFirstChildOfClass("StringValue")
	print(swordtype)
	print(weapon)
	
	for _, oldweapon in pairs(hand:GetChildren()) do
		if oldweapon:FindFirstChild("Handle") then
			oldweapon:Destroy()
		end
	end
			
	
	
-------------------------------------WELD SENDER-------------------------------------------
	if sheathed == true then
		
		print("we not there yet")
		
	else
		
		if swordtype.Name == "Longsword" then
		        local equipped = weapon:Clone()
			    LongswordToHandWeld(plr, equipped)
                equipped.Parent = hand
		end
		
	end
-------------------------------------------------------------------------------------------	
	
	
end)

--// WELD FUNCTIONS \\--

function LongswordToHandWeld(plr, weapon)
	char = plr.Character
	
	local SwordToHand = Instance.new("Weld")
		SwordToHand.Name = "SwordToHand"
		SwordToHand.Parent = weapon
		SwordToHand.Part0 = weapon.Handle
		SwordToHand.C0 = CFrame.new(0,-.38,0) * CFrame.Angles(0,0,0)
		SwordToHand.Part1 = char.RightHand
		
		char.Animate.idle.Animation1.AnimationId = "rbxassetid://5008254428"
		char.Animate.run.RunAnim.AnimationId = "rbxassetid://5008311723"
		plr.Character.Dasher.Dash.AnimationId = "rbxassetid://5008809963"
end 
1 Like

This works! Thanks so much :smiley:

1 Like