I wanted to change the default idle animation but I went through a lot of issues and I am kind of lost right now. This is my first post here and im new so sorry if my formatting is bad.
The first things I tried to do was following this thread which also included a video. I followed the thread but after the animation finished it didn’t loop.
I saw another thread and got a looping idle animation localscript that worked:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local idleAnimation = Instance.new("Animation")
idleAnimation.AnimationId = "rbxassetid://4657922943"
local loadedAnimation = humanoid:LoadAnimation(idleAnimation)
loadedAnimation.Looped = true
humanoid.Running:Connect(function(speed)
if speed > 0
and not jumping
then
print ("RUNNING")
loadedAnimation:Stop()
elseif speed == 0 and not jumping then
print("STOPPED")
loadedAnimation:Play()
end
end)
The idle animation did work and it was looping but I ran into another problem. When I was holding space to jump, the idle animation plays anyways.
To fix this, I added a variable so it would check if I was holding space before it was playing the animation:
-- Services
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local idleAnimation = Instance.new("Animation")
idleAnimation.AnimationId = "rbxassetid://4657922943"
local loadedAnimation = humanoid:LoadAnimation(idleAnimation)
loadedAnimation.Looped = true
local jumping = false
humanoid.Running:Connect(function(speed)
if speed > 0
and not jumping
then
print ("RUNNING")
loadedAnimation:Stop()
elseif speed == 0 and not jumping then
print("STOPPED")
loadedAnimation:Play()
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
jumping = true
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
jumping = false
end
end)
It fixed itself and the idle animation didn’t play at all when I was jumping but I ran into another problem. When I land while I am holding space I will randomly move slightly to a random direction. There are also instances where I move very far and sometimes even off the baseplate.
Note: I am only holding space during this video.
Couldn’t upload video so I put it in Google Drive
Here is also my double jump localscript:
-- Services
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
--Player
local plr = game.Players.LocalPlayer
local HumanoidRootPart = plr.character:WaitForChild("HumanoidRootPart")
local Humanoid = workspace:WaitForChild(plr.Name).Humanoid
Humanoid.JumpPower = 100
--Variables
local dbDoubleJump = true
local dbJump = false
--Animation
local doubleJumpAnimation = Instance.new("Animation")
doubleJumpAnimation.AnimationId = "rbxassetid://05109822254"
local doubleJumpTrack = Humanoid:LoadAnimation(doubleJumpAnimation)
local firstJumpAnimation = Instance.new("Animation")
firstJumpAnimation.AnimationId = "rbxassetid://05109816805"
local firstJumpTrack = Humanoid:LoadAnimation(firstJumpAnimation)
Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
print("FIRSTJUMP")
dbDoubleJump = true
dbJump = false
end
end)
Humanoid.StateChanged:Connect(function(old, new)
if new == Enum.HumanoidStateType.Jumping then
firstJumpTrack:Play()
end
end)
-- Check if space and flags are true
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space and dbDoubleJump and dbJump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
doubleJumpTrack:Play()
print("DOUBLEJUMP")
dbDoubleJump = false
end
end)
-- Check if Space is released
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
dbJump = true
end
end)