Why is my weapons dissapearing?

whenever i equip my weapon from my inventory, it gets deleted from my inventory a few seconds after i equip it, why does this happen? this is the script inside the weapon

local character = player.Character or player.CharacterAdded:Wait() 
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")


local connection = nil
local idle, run
local LDagger = script.Parent.LDagger
local RDagger = script.Parent.RDagger

local function CreateAnimationTrack(animationId, looped)
	assert(typeof(animationId) == "number", 'CreateAnimationTrack Error: "animationId" must be a number value!')
	assert(typeof(looped) == "boolean", 'CreateAnimationTrack Error: "looped" must be a boolean value!')

	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://"..animationId

	local animationTrack = animator:LoadAnimation(animation)
	animationTrack.Looped = looped
	animationTrack.Priority = Enum.AnimationPriority.Action

	return animationTrack
end

local function OnPostSimulation()
	if humanoid.MoveDirection == Vector3.zero then 
		if idle.IsPlaying then return end 

		run:Stop()
		idle:Play()
	else 
		if run.IsPlaying then return end

		idle:Stop()
		run:Play()
	end
end

local function OnEquipped()
	if connection then return end 

	connection = RunService.PostSimulation:Connect(OnPostSimulation)
	
end

local function OnUnequipped()
	if connection then
		connection:Disconnect()
		connection = nil

		
		if idle.IsPlaying then idle:Stop() end
		if run.IsPlaying then run:Stop() end
	end
end


idle = CreateAnimationTrack(85281865286630, true)
run = CreateAnimationTrack(91289823710220, true)

tool.Equipped:Connect(OnEquipped)
tool.Unequipped:Connect(OnUnequipped)

this is the contents inside the tool (i want there to be two weapons in each player hand)

Where did player get defined here?

local tool = script.Parent
local character = tool.Parent

or

local Players = game:GetService("Players")
local Player = Players:GetPlayerFromCharacter(tool.Parent)

oh yeah thats my bad i accidentally cut out the top part, this is how the player is defined

local Players = game:GetService("Players") 
local RunService = game:GetService("RunService")

local tool = script.Parent

local player = Players.LocalPlayer

After looking at your script and doing a bit of research I’m still not sure.
One thing that kind of stands out is …

You’re using Animator:LoadAnimation(…) in a LocalScript …
That API is deprecated on the client for Humanoid.Animator.

how can i fix that part of the animation being loaded in a server script instead of the local script?

Well, you could do the animation logic in a ServerScript within the tool.

local RunService = game:GetService("RunService")
local tool = script.Parent

local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "rbxassetid://85281865286630"

local runAnim = Instance.new("Animation")
runAnim.AnimationId = "rbxassetid://91289823710220"

local idleTrack, runTrack, conn

tool.Equipped:Connect(function()
	local char = tool.Parent
	local animator = char.Humanoid.Animator
	idleTrack = animator:LoadAnimation(idleAnim)
	runTrack = animator:LoadAnimation(runAnim)
	idleTrack.Looped = true
	runTrack.Looped = true
	idleTrack.Priority = Enum.AnimationPriority.Action
	runTrack.Priority = Enum.AnimationPriority.Action

	conn = RunService.PostSimulation:Connect(function()
		if char.Humanoid.MoveDirection.Magnitude < 0.1 then
			if not idleTrack.IsPlaying then
				runTrack:Stop()
				idleTrack:Play()
			end
		else
			if not runTrack.IsPlaying then
				idleTrack:Stop()
				runTrack:Play()
			end
		end
	end)
end)

tool.Unequipped:Connect(function()
	conn:Disconnect()
	idleTrack:Stop()
	runTrack:Stop()
end)

i was testing it out and i found out why it was deleting when in my inventory, it only did it when i used these two handles, i want to make it so it doesnt delete and stays on the player hands, can you find whats wrong with the daggers?

Nice tracking down the issue. I can’t really look at all you’re dealing with here.
For a tool anything added to the tool can be welded to the handle. What you’re showing don’t look like the tool’s handle. If they are, they are missing some things that should be in them. Look at some of your other tool handles. Also… is everything set to Archivable…

If the joint is taking the place of the weld make sure that is connected between two parts.

I took out the two handles off the tool while i was finding out that they are the problem, and i added joints to them because in the script i showed before, i added that so when the player equips the tool the part0 of the joint welds to those players hands, but i removed the script to try find why the tool was deleting on being equipped, the tools were able to weld fine when i was animating them with a rig

I can’t tell if you need the joints or not, they may be part of the animation… Try just welding that part to the handle to see if that stops them for being removed. They may be attached to the something that isn’t there when put in the backpack… like the hand. Then they drop off… this will take some testing.

When I make tools and add things to the tools I like to use Weld.
I made my own version of this but this one is almost the same. It works well.
(the last one you click will hold the welds within it)

how did you use the weld plugin to weld a weapon to the player? did you make it a tool as well?

Click on the part then hold alt and click on the handle then press weld. You’re welding the extra parts to the tool’s handle.

how do i make that part the players arm?

You should load and play animations on the client if the Animator is a descendant of the player’s character. Animations should be loaded on the server if the Animator is owned by the server.

That’s what it says in the documentations, at least.

Are you attaching the joints to the player on the server as well? It won’t realize the handles are attached to the player if it’s only done locally, and the tool will fall into the void (if it has collision disabled, that is)

Looks like you are right on this. Not sure where I read to try and stay on the server. Clearly that is not entirely true.

1 Like

ive only tried adding joints in the client script, the animations work fine and well with the local script, the only problem is the two handles not connecting to the player and instead falling out the world (they are both unanchored and cancollide is off)

Easy! You can add a server script that, upon detecting the tool being equipped, connects the joints from the handles to the character’s right arm and left arm.
If you’re not planning on making the tool droppable, there’s no need to detach them. Otherwise, just detect when the tool’s parent changes to workspace. Not sure if that’s the best way to handle that but that’s what I know.

I was able to make an event sent to the server to make part0 the players arms, but the weapons stay in the exact same place instead of teleporting to the players arms, and its unanchored, do you know what going on?

1 Like

actually, i was able to simply fix this by making the daggers the parent of the player, i forgot to add that :sweat_smile:
they weld fine now

1 Like