#How to script custom jumping animation
1 messages · Page 1 of 1 (latest)
-- AnimationController.server.lua (StarterCharacterScripts)
-- Plays Idle, Run, Jump and Fall on the server so every client sees the same thing.
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- 1) Put your animation asset IDs here once you upload them in Roblox
local AnimationIds = {
Idle = "rbxassetid://12345678",
Run = "rbxassetid://23456789",
Jump = "rbxassetid://34567890",
Fall = "rbxassetid://45678901",
}
-- 2) Pre‑load tracks so we can switch instantly
local tracks = {}
for state, id in pairs(AnimationIds) do
local anim = Instance.new("Animation")
anim.Name = state .. "Anim"
anim.AnimationId = id
anim.Parent = script
tracks[state] = animator:LoadAnimation(anim)
tracks[state].Priority = Enum.AnimationPriority.Movement
end
local currentTrack
local function play(trackName, fadeTime)
if currentTrack and currentTrack.IsPlaying then
currentTrack:Stop(fadeTime or 0.15)
end
currentTrack = tracks[trackName]
if currentTrack then
currentTrack:Play(fadeTime or 0.15)
end
end
-- 3) React to Humanoid state changes
humanoid.StateChanged:Connect(function(_, new)
if new == Enum.HumanoidStateType.Running then
-- Humanoid reports “Running” both when standing still (speed 0)
-- and when actually moving. Use the MoveDirection magnitude to decide.
if humanoid.MoveDirection.Magnitude > 0.1 then
play("Run")
else
play("Idle")
end
elseif new == Enum.HumanoidStateType.Jumping then
play("Jump")
elseif new == Enum.HumanoidStateType.Freefall
or new == Enum.HumanoidStateType.FallingDown then
play("Fall")
elseif new == Enum.HumanoidStateType.Landed then
play("Idle")
end
end)
-- 4) Small loop to keep Idle vs Run in sync with speed every 0.25 s
while true do
task.wait(0.25)
if humanoid:GetState() == Enum.HumanoidStateType.Running then
if humanoid.MoveDirection.Magnitude > 0.1 then
if currentTrack ~= tracks.Run then
play("Run")
end
else
if currentTrack ~= tracks.Idle then
play("Idle")
end
end
end
end
Upload/own the four animation assets in Roblox → copy each numeric ID into AnimationIds.
Drop this Script (not a LocalScript) into StarterCharacterScripts so it runs once per character on the server — that means everyone sees exactly the same animation states, and exploiters can’t spoof local motions.
Delete or disable any default Animation script Roblox inserts, or they’ll fight over Humanoid states.
wdym delete like remove their code? Btw tysm for this
Yh just replace it with this code