Animation is inaccurate

So this is the final problem for my sword framework here is some Expected and Unexpected results

Expected:
image

  • Keep that Animation while moving
  • Keep it like that even idling

Unexpected Results:

Code

Client:

-- // Services \\ --
local UIS = game:GetService("UserInputService")

-- // Variables \\ --
local Tool = script.Parent.Parent.Parent.Parent
local Events = Tool:WaitForChild("Events")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Humanoid = Character.Humanoid

-- // For Shiftlock \\ --
local PlayerScripts = Player.PlayerScripts
local Values = PlayerScripts.Values
local IsHoldingTool = Values.IsHoldingTool

-- // For UI \\ --
local PlayerGui = Player.PlayerGui
local WeaponMouseIcon = PlayerGui.WeaponMouseIcon

-- // Events \\ --
local PLAY_ANIMATION_EVENT = Events.PlayAnimation
local CHANGE_MOUSE_EVENT = Events.ChangeMouse
local SHIFTLOCK_EVENT = Events.Shiftlock

-- // Animation Tracks \\ --
local AnimationsFolder = Tool.Animations
local SWING_ANIMATION = AnimationsFolder.Swing
local HOLD_ANIMATION = AnimationsFolder.Hold

PLAY_ANIMATION_EVENT.OnClientEvent:Connect(function(AnimationName)
	if AnimationName == "Hold" then
		local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)
		
		-- Play it bruh lol
		print("working")
		HOLD_ANIMATION_TRACK:Play()
	elseif AnimationName == "Swing" then
		local SWING_ANIMATION_TRACK = Humanoid:LoadAnimation(SWING_ANIMATION)
		local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)
		
		-- Play it bruh lol
		print("working")
		HOLD_ANIMATION_TRACK:Stop()
		SWING_ANIMATION_TRACK:Play()
	elseif AnimationName == "StopHold" then
		local HOLD_ANIMATION_TRACK = Humanoid:LoadAnimation(HOLD_ANIMATION)

		-- Play it bruh lol
		print("working")
		HOLD_ANIMATION_TRACK:Stop()
	end
end)

CHANGE_MOUSE_EVENT.OnClientEvent:Connect(function(MouseIcon)
	if MouseIcon == "WeaponMouseIcon" then
		UIS.MouseIconEnabled = false
		WeaponMouseIcon.Enabled = true
	elseif MouseIcon == "DefaultMouseIcon" then
		UIS.MouseIconEnabled = true
		WeaponMouseIcon.Enabled = false
	end
end)

SHIFTLOCK_EVENT.OnClientEvent:Connect(function(Response)
	if Response == "Enable" then
		IsHoldingTool.Value = true
	elseif Response == "Disable" then
		IsHoldingTool.Value = false
	end
end)

Server:

-- // Services \\ --

local RunService = game:GetService("RunService")

-- // Variables \\ --

local Tool = script.Parent.Parent.Parent.Parent
local Events = Tool.Events

-- // Events \\ --

local PLAY_ANIMATION_EVENT = Events.PlayAnimation
local CHANGE_MOUSE_EVENT = Events.ChangeMouse
local SHIFTLOCK_EVENT = Events.Shiftlock

-- // Functions \\ --
local function Yield(s)
	local t = tick()
	while tick()-t < s do RunService.Stepped:wait() end
	return tick()-t
end

Tool.Equipped:Connect(function()
	-- Make Motor 6D {first we need the player's character}
	local Character = script.Parent.Parent.Parent.Parent.Parent
	local Player = game.Players:GetPlayerFromCharacter(Character)
	local RightHand = Character.RightHand
	
	-- Creation of Motor6D
	local Motor6D = Instance.new("Motor6D")
	Motor6D.Name = "Motor6D"
	Motor6D.Parent = RightHand
	
	Motor6D.Part0 = RightHand
	Motor6D.Part1 = Tool.SwordHandle
	
	PLAY_ANIMATION_EVENT:FireClient(Player, "Hold")
	CHANGE_MOUSE_EVENT:FireClient(Player, "WeaponMouseIcon")
	SHIFTLOCK_EVENT:FireClient(Player, "Enable")
	
end)

Tool.Unequipped:Connect(function()
	-- Remove Motor6D
	local Player = script.Parent.Parent.Parent.Parent.Parent.Parent
	local Character = Player.Character
	local RightHand = Character.RightHand
	
	-- Removal of MOtor6D
	local Motor6D = RightHand.Motor6D
	
	Motor6D.Part0 = nil
	Motor6D.Part1 = nil
	
	Motor6D:Destroy()
	
	PLAY_ANIMATION_EVENT:FireClient(Player, "StopHold")
	CHANGE_MOUSE_EVENT:FireClient(Player, "DefaultMouseIcon")
	SHIFTLOCK_EVENT:FireClient(Player, "Disable")
	
end)

Tool.Activated:Connect(function()
	-- Set Debounce to true then after a few milliseconds then to false
	local Player = script.Parent.Parent.Parent.Parent.Parent
	local Values = Tool.Values
	local SwordDebounce = Values.SwingDelay
	
	if SwordDebounce == false then
		SwordDebounce = true
		
		PLAY_ANIMATION_EVENT:FireClient(Player, "Swing")
		
		Yield(.5)
		SwordDebounce = false
	end
end)

I did it it from this tutorial

The Only Solutions I tried was gripping it but doesn’t work but another one is from the coding but it doesn’t work neither I need an good solution for this problem because this is an essential part of my game thanks!

#1 Problem Sword Rotation is Inaccurate: Solved
but I still need a way to keep it like when the player moves it doesn’t mess up anything else in the animation any suggestions?

I believe the issue is caused by the default animations blending in with the newer animations that you have made. I believe the easier solution should be to change the default animation script ID’s like so to eliminate the animation blending with the default animation entirely and just use your own animations like so from the article on changing the default animations.

	local animateScript = character:WaitForChild("Animate")
	animateScript.run.RunAnim.AnimationId = "rbxassetid://616163682"        -- Run
	animateScript.walk.WalkAnim.AnimationId = "rbxassetid://616168032"      -- Walk
	animateScript.idle.Animation1.AnimationId = "rbxassetid://616158929"    -- Idle (Variation 1)
	animateScript.idle.Animation2.AnimationId = "rbxassetid://616160636"    -- Idle (Variation 2)

Alternatively set the animation weight so high that the new animations override the default animations:

3 Likes

I’m not entirely sure about this but how do I get the animation module so that I can change it for that player everytime they equip that sword?

or just how to change its default animations set by roblox

It’s not really an animation module it’s a local animation script within the character which should be modifiable.

local Character = Player.Character or Player.CharacterAdded:wait()
local animateScript = Character:WaitForChild("Animate")