Motor6d animated tool not working after respawn

Hello i am working on a flintlock with animations using motor6d to animate the tools parts but as of testing i have encountered annoying issue


before reseting character

after reseting character
So if you reset, the tool would just stay on that one part of the baseplate
Note that i am a newbie at scripting so try to explain in simple terms if you can

I tried for quite a while to find a solution and i will list some things i tried

  • How to ANIMATE TOOLS | HowToRoblox video.

This video was very helpful and in fact i used the coding for this one, this was one of the only working ones i knew but no where in the video had explained about the reset bug, i checked the comments to see if anyone had answered someone who had the same problem as me but did not find anything.

  • How to animate Tool Parts (Guns, Knifes etc.) tutorial on devfourm.

This was the first tutorial i found but failed to understand. The tutorial didn’t tell where the scripts should be placed and confused me. At first i thought i messed with with rigging and tried again but that wasnt the case.

  • Code assistant

Code assistant looked trust worthy at first but all the scripts it made had not work.

  • Ai scripter
    By saying – (text) in a script would have an ai talk to you and try to help but this time, it was not really helpful. Instead of telling me a way to fix it or attempting to, it just end up mocking my text or giving me suggestions to expand the game instead of helping with the script, but thats a different topic for later.

As of right now, im quite in a pickle because i cannot find a way to fix this besides asking the community to help, i will list the code and explorer so you can review it.

image
image
image

game.Players.PlayerAdded:Connect(function(plr)			
	plr.CharacterAdded:Connect(function(char)
				
		local M6D = Instance.new("Motor6D")
		M6D.Name = "ToolGrip"
		M6D.Parent = char.UpperTorso
    end)
end)

game.ReplicatedStorage.ConnectM6D.OnServerEvent:Connect(function(plr, location)

      local char = plr.Character
      char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
      char.UpperTorso.ToolGrip.Part1 = location
end)

game.ReplicatedStorage.DisconnectM6D.OnServerEvent:Connect(function(plr)
	
    plr.Character.UpperTorso.ToolGrip.Part1 = nil
end)
-- this is GunServer
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local tool = script.Parent


local idleAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.IdleAnim)
local shootAnim = char:WaitForChild("Humanoid"):LoadAnimation(script.ShootAnim)


tool.Equipped:Connect(function()

	game.ReplicatedStorage.ConnectM6D:FireServer(tool.BodyAttach)
	
	char.UpperTorso.ToolGrip.Part0 = char.UpperTorso
	char.UpperTorso.ToolGrip.Part1 = tool.BodyAttach
	
	
	idleAnim:Play()
end)

tool.Unequipped:Connect(function()

	game.ReplicatedStorage.DisconnectM6D:FireServer()
	
	idleAnim:Stop()
end)



tool.Activated:Connect(function()
	
	shootAnim:Play()
end)
-- this is guncilent inside the flintlock

Hopefully this is enough for you to help me and be able to help many others

Try destroying the tool whenever the player dies. You only referenced the player and character once in the scripts, so once the player dies, the variables became nil.
By destroying the tool, you’ll reset the variables in the scripts.
For this, I recommend using this:

hum.HealthChanged:Connect(function()
	if hum.Health <= 0 then
		ThisEvent:FireServer()
	end
end)

Put in a local script, and do the killing in a server script. I tried using “hum.Died” before and it didn’t work and I don’t want you to waste nearly an hour trying to figure it out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.