I need help regarding my CFrame animation module

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to remove flickering from my animations, I’m not a very experienced programmer and i’ve tried using ChatGPT and Assistant, but both seem unable to fix the issue.

  2. What is the issue? Include screenshots / videos if possible!
    Flickering between different animations

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    ChatGPT and Assistant, but I have not looked on the Creator Hub.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Here’s my animation player.

-- Apply lerp between frames
function Animator:ApplyFrameLerp(frame1, frame2, alpha)
	local rootPart = self.Character:FindFirstChild("HumanoidRootPart")
	if not rootPart then return end

	for partName, joint in self.Joints do
		if not (joint and joint:IsA("Motor6D")) then continue end

		local c1 = self:GetCFrameFromFrame(frame1, partName)
		local c2 = self:GetCFrameFromFrame(frame2, partName)

		
		local blended = c1:Lerp(c2, alpha)

		
		local base = self.Defaults[partName]
		if base then
			joint.C0 = base * blended
		end
	end
end

What i’m trying to do with a script:

local Character = script.Parent
local SprintEvent = Character:WaitForChild("Event")
local Humanoid = Character:WaitForChild("Humanoid")

local WALK_SPEED = 16
local SPRINT_SPEED = 32

local CFrameAnimator = require(game.ReplicatedStorage:WaitForChild("CFrameAnimator"))
local Animator = CFrameAnimator.new(Character)
local CurrentState = nil

local Animations = game.ReplicatedStorage:WaitForChild("Animations")
local IdleAnim = Animations:FindFirstChild("idle")
local WalkAnim = Animations:FindFirstChild("walk")
local RunAnim = Animations:FindFirstChild("run")

-- Track last known movement
local LastMoveDir = Vector3.new()
local Sprinting = false

-- Debounce for event handling
local lastEventTime = 0
local EVENT_COOLDOWN = 0.1 -- seconds

local function PlayStateAnimation(state, speed)
	-- Only change animation if state actually changes
	if CurrentState == state then
		return
	end
	CurrentState = state

	if state == "Idle" and IdleAnim then
		Animator:Play(IdleAnim, 1)
	elseif state == "Walk" and WalkAnim then
		Animator:Play(WalkAnim, 1)
	elseif state == "Run" and RunAnim then
		Animator:Play(RunAnim, 3)
	end
end

-- Receive input from client
SprintEvent.OnServerEvent:Connect(function(player, sprinting, moveDir)
	local now = tick()
	if now - lastEventTime < EVENT_COOLDOWN then
		return -- Ignore rapid repeated events
	end
	lastEventTime = now

	Sprinting = sprinting
	LastMoveDir = moveDir
	Humanoid.WalkSpeed = sprinting and SPRINT_SPEED or WALK_SPEED

	if sprinting and moveDir.Magnitude > 0 then
		PlayStateAnimation("Run", 3)
	elseif moveDir.Magnitude > 0 then
		PlayStateAnimation("Walk", 1)
	else
		PlayStateAnimation("Idle", 1)
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Why are you using a server script specifically? CFrames are pretty expensive
When does sprintevent fire? Is it only when you hold/stop holding a sprint key? Or do you fire it every frame or something of that sort
And a bit unrelated, but why are you trying to make your own cframe animator instead of using Roblox’s? Unless it’s for practice

I’m pretty sure the issue has to do with the sprintevent itself, can we get the localscript that it’s fired in?

Yeah, here it is:

local player = game.Players.LocalPlayer
local character = script.Parent
local SprintEvent = character:WaitForChild("Event")
local UIS = game:GetService("UserInputService")

local lastMove = Vector3.new()
local lastSprinting = false
local sprinting = false

-- Helper to send event only when state changes
local function sendSprintEvent()
	if sprinting ~= lastSprinting or lastMove ~= character.Humanoid.MoveDirection then
		SprintEvent:FireServer(sprinting, character.Humanoid.MoveDirection)
		lastSprinting = sprinting
		lastMove = character.Humanoid.MoveDirection
	end
end

-- Track sprint input
UIS.InputBegan:Connect(function(input, gp)
	if gp then return end
	if input.KeyCode == Enum.KeyCode.LeftShift then
		sprinting = true
		sendSprintEvent()
	end
end)

UIS.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		sprinting = false
		sendSprintEvent()
	end
end)

-- Track movement direction changes
local humanoid = character:WaitForChild("Humanoid")
humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	sendSprintEvent()
end)

-- Fire initial state
sendSprintEvent()

like i said, i’m a new programmer, i don’t think i’ll know as much…
Edit: Wait… (sorry i see my issue thanks for your time)

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