Help with managing Motor6D Manpulation

I am making my very own custom animate script

I have a problem: An animation (made of math) plays, when another animation is about to play. It actually doesn’t appear and freezes the previous animation until idle.

I can’t simply just stop the previous RemoteEvent because it probably isn’t possible.

Here’s the code:

  1. Server:

local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)

Players.PlayerAdded:Connect(function(player)
local ReplicationFolder = Instance.new(“Folder”, ReplicatedStorage.Animator)
ReplicationFolder.Name = player.Name

local IdleAnim = Instance.new("RemoteEvent", ReplicationFolder)
local WalkAnim = Instance.new("RemoteEvent", ReplicationFolder)

IdleAnim.Name = "Idle"
WalkAnim.Name = "Walk"
player.CharacterAdded:Connect(function(character)

	local humanoid = character:WaitForChild("Humanoid")

	local isMoving = false
	local isRunning = false

	humanoid.StateChanged:Connect(function(_, newState)
		if newState == Enum.HumanoidStateType.Running then
			isMoving = true

			if isMoving == true then
				isRunning = true
				WalkAnim:FireAllClients(player)
			end
		else
			if isMoving == false then
				isRunning = false
				IdleAnim:FireAllClients(player)
			end
		end
	end)
end)

end)

  1. Local:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local RunService = game:GetService(“RunService”)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

local humanoid = character:WaitForChild(“Humanoid”)

local Torso = character:WaitForChild(“Torso”)
local HRP = character:WaitForChild(“HumanoidRootPart”)

local Motor6D = {
RootJoint = HRP:WaitForChild(“RootJoint”),
Neck = Torso:WaitForChild(“Neck”),
Shoulders = {
LeftShoulder = Torso:WaitForChild(“Left Shoulder”),
RightShoulder = Torso:WaitForChild(“Right Shoulder”)
},
Hips = {
LeftHip = Torso:WaitForChild(“Left Hip”),
RightHip = Torso:WaitForChild(“Right Hip”)
}
}

local remoteEventWalk = ReplicatedStorage.Animator:WaitForChild(player.Name):FindFirstChild(“Walk”)
local remoteEventIdle = ReplicatedStorage.Animator:WaitForChild(player.Name):FindFirstChild(“Idle”)

remoteEventWalk.OnClientEvent:Connect(function()
if humanoid:GetState() == Enum.HumanoidStateType.Running then
local deg = 0
local deg2 = 0

	while humanoid:GetState() == Enum.HumanoidStateType.Running do
		deg = deg + 1
		deg2 = deg2 - 1

		local rZ = math.sin(math.rad(deg) * (4)) * 1
		local rZ2 = math.sin(math.rad(deg2) * (4)) * 1

		local cframe = CFrame.Angles(0, 0, rZ)
		local cframe2 = CFrame.Angles(0, 0, rZ2)

		Motor6D.Hips.LeftHip.Transform = cframe2
		Motor6D.Hips.RightHip.Transform = cframe2
		Motor6D.Shoulders.LeftShoulder.Transform = cframe
		Motor6D.Shoulders.RightShoulder.Transform = cframe

		RunService.Heartbeat:Wait()
	end
end

end)

remoteEventIdle.OnClientEvent:Connect(function()
local deg = 0
local deg2 = 0

RunService.Heartbeat:Connect(function()
	deg = deg + 1
	deg2 = deg2 - 1

	local rZ = math.sin(math.rad(deg) * 0.25) * 0.1
	local rZ2 = math.sin(math.rad(deg2) * 0.25) * 0.1

	local cframe = CFrame.Angles(0, 0, rZ)
	local cframe2 = CFrame.Angles(0, 0, rZ2)

	Motor6D.Hips.LeftHip.Transform = cframe2
	Motor6D.Hips.RightHip.Transform = cframe2
	Motor6D.Shoulders.LeftShoulder.Transform = cframe
	Motor6D.Shoulders.RightShoulder.Transform = cframe
end)

end)

You can give me an example about how I could approach the problem.

Sorry if the code thingy is a mess, because DevForum likes to mess up the code which makes this effect.

I have had this issue before, see if this helps maybe:

I also attached a link into my message to take you to the community tutorials I made exactly relating to this.

The community tutorials page:

1 Like

The idle animation and walk animation works.
The problem is how you can manage it.

Idk how i can solve a problem.
You should copy and paste both server (serverscriptservice) and local (statercharacterscripts)
You also need to delete the already existing animator.

Maybe with that, you will understand what’s going on.

You also need an r6 character

I’m using the “new” transform feature and it works fine.
It’s how you manage the remote events i think.

I mean, to make an animation you can just make a variable, then call it?

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local animation = character.Humanoid:WaitForChild("Animator"):LoadAnimation(animation)
        while task.wait(10) do animation:Play() end
    end)
end)

Let this be a template.

Wait, are you trying to delete the Animator, then try to animate your own animations?
I don’t think that’s possible.

Otherwise, I don’t know what your goal is.

actually it is possible to make anims using motor6d.
motor6d manipulates the position and axis of a certain part without the need of the animator script.

It’d be extremely difficult to do?
Just use animations, you don’t need to manipulate specific Motor6Ds in specific times.

It seems like you’re trying to create a custom animation system for your game, but you’re encountering issues when transitioning between different animations. The code you provided is quite complex and involves both server and client scripts.

One approach to handle animation transitions smoothly is to use a state machine for your animations. A state machine helps manage different animation states (such as idle, walking, running) and ensures smooth transitions between them. Instead of directly changing the animations using RemoteEvents, you could use a state machine to handle animation changes.

Here’s a simplified example of how you could structure your animation using a state machine approach:

  1. Define Animation States: Create an enumeration or a table that defines your animation states, such as Idle, Walking, Running.
  2. Server Script: In your server script, you can set the current animation state for each player and broadcast it to all clients using a RemoteEvent.

luaCopy code

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

local AnimationStates = {
    Idle = "Idle",
    Walking = "Walking",
    Running = "Running",
}

Players.PlayerAdded:Connect(function(player)
    local currentState = AnimationStates.Idle -- Initial state

    local remoteEvent = Instance.new("RemoteEvent")
    remoteEvent.Name = "AnimationEvent"
    remoteEvent.Parent = player

    remoteEvent.OnServerEvent:Connect(function(newAnimationState)
        if AnimationStates[newAnimationState] then
            currentState = newAnimationState
            remoteEvent:FireAllClients(currentState)
        end
    end)
end)
  1. Client Script: On the client side, you can listen to the RemoteEvent and update the animations based on the current animation state.

luaCopy code

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

local remoteEvent = ReplicatedStorage:WaitForChild("AnimationEvent")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local currentAnimationState = "Idle"

remoteEvent.OnClientEvent:Connect(function(newAnimationState)
    currentAnimationState = newAnimationState
end)

UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local isMoving = humanoid.WalkSpeed > 0
        if input.KeyCode == Enum.KeyCode.W then
            remoteEvent:FireServer(isMoving and AnimationStates.Walking or AnimationStates.Idle)
        elseif input.KeyCode == Enum.KeyCode.LeftShift then
            remoteEvent:FireServer(isMoving and AnimationStates.Running or AnimationStates.Idle)
        end
    end
end)

-- Update animations based on currentAnimationState
-- Implement the logic for each animation state

In this approach, the server sets and manages the current animation state for each player. The client listens to the changes and updates animations accordingly. This can help you achieve smoother animation transitions and avoid potential conflicts when trying to play multiple animations simultaneously.

You’re not allowed to give out entire scripts to people, but great explanation nevertheless.

Edit: That’s 100% ChatGPT

I want to approach things, not to copy and paste, but thanks, I guess…

I will make a new place to test your stuff.

If your animation plays whilst another is playing, try to cancel it before the new animation begins to play?

i didn’t mean to giveaway the whole script i actually meant it as a example but its good if you can use it

idk how to cancel a motor6d animation.
motor6d is very different compared to regular animation as it manipulates the cframe (c0 and c1) of each limb (including the hrp).

motor6d, unlike traditional animation allows for mathematical animations to be made (which means in theory, i can make inappropiate animations using math)

you don’t seem to understand motor6d, don’t ya? :wink:

that’s fine, i will just make another place to use it and maybe replace the existing system.

“Cancel a Motor6D animation”

Just set all of the C0’s to their default values.
Just like the Right Shoulder Motor6D’s default value is (0,90,0).

if you use inappropiate animations you will most likely get terminated

Guys, this post has been given a solution.
Can we stop speaking unless it’s actually important to this?

ye good idea i will be silent now