Why is my animation snappy first time, but not second time?

Hey people

I’ve been struggeling with a problem for a while now.
My animation is being weird. Look for yourself

I don’t know why it’s so snappy the first time, then so good the second time.

-- check for beam hit, created when using beam. beam hit is in Humanoid
local remote = game:GetService("ReplicatedStorage"):WaitForChild("onBeamHit")


local NPChumanoid = script.Parent.Humanoid


local isBeamHit = false

local isPlaying = false

remote.OnServerEvent:Connect(function(player, humanoid)
	if not isPlaying then
		local beamHit = NPChumanoid:WaitForChild(player.Name.. " beamHitPart")

		repeat wait() until NPChumanoid[player.Name.. " beamHitPart"]
		if NPChumanoid:FindFirstChild(player.Name.. " beamHitPart") then

			local animation = script:WaitForChild('goAir')
			local humanoid = script.Parent:WaitForChild('Humanoid')
			local goAir = humanoid:LoadAnimation(animation)

			local animation = script:WaitForChild('onBeamHit')
			local humanoid = script.Parent:WaitForChild('Humanoid')
			local onBeamHit = humanoid:LoadAnimation(animation)


			goAir:Play()
			isPlaying = true

			goAir.KeyframeReached:Connect(function(keyframe)
				if keyframe == "startOther" then
					goAir:AdjustSpeed(0)
					onBeamHit:AdjustWeight(1)
					onBeamHit:Play()
					goAir.KeyframeReached:Connect(function(keyframe2)
						if keyframe2 == "inAir" then
							goAir:Stop()
						end
					end)
					
				end
				
				if humanoid.Health <= 0 then
					isPlaying = false
					onBeamHit:Stop()
				end
			end)
		end
	end
end)

I’ve tried anything i can think off.
Adjusting speed, weight, timing…

Sorry for if i have typos. It’s 2am lol.

Any ideas?
Thank you for reading

Don’t quote me on this, but I think it has something to do with the animation initially loading. This exact same thing has happened for all the animations I’ve made aswell, and they always work fine once they have been ran once. - Not sure if there’s any fix though…
Edit: Unless you run the animation on a dummy / a person at the start of the game? Haven’t tested that though, probably won’t work

2 Likes

mhm, that’s weird. I hope there is a fix. Cuz it’s so bad to look at.

just saw ur edit, imma try that

mhm, looks like you’re right. Played it first on a random dummy, then it works smoothly.
That’s weird tho.

But it works, so i can finally sleep.
Thanks

@Orbular3 Actually it will and I have the code right here
You need to place a character called Dummy into the script for it to work, the script is a regular script in ServerScriptService. It takes a few seconds to load but overall I think it does the trick

local ContentProvider = game:GetService("ContentProvider")

local gameAssets = game:GetDescendants()
local animations = {}

local dummy = script:WaitForChild("Dummy"):Clone()
dummy.Parent = workspace

local speed = math.huge

for _,v in pairs(gameAssets) do	
	if v:IsA("Animation") then
		ContentProvider:PreloadAsync({v})
		
		local animationTrack = dummy:WaitForChild("Humanoid"):LoadAnimation(v)
		animationTrack:Play()
		
		animationTrack:AdjustSpeed(speed)
		wait(animationTrack.Length / speed)
		
		animationTrack:Stop()
	end
end

dummy:Destroy()

Also sorry for being late :stuck_out_tongue:

2 Likes