I’ve never scripted animations before, so this is my first time doing it but I am unfortunately struggling. I’ve been going at it with this script for like a solid week and I’ve made no progress. I’ve even tried to see if ChatGPT could help me understand what I’m doing wrong, but it’s no good either.
local StarterPlayer = game:GetService("StarterPlayer")
local humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local animationIds = {
beingRevived = "rbxassetid://13956810525",
reviving = "rbxassetid://13956955414",
downedIdle = "rbxassetid://13956860997",
downedMoving = "rbxassetid://13956866584",
crouchIdle = "rbxassetid://13956850946",
crouchMoving = "rbxassetid://13956854919",
crawlIdle = "rbxassetid://13956843888",
crawlMoving = "rbxassetid://13956846671",
jump = "rbxassetid://13956888748",
holdingObject = "rbxassetid://13956937717",
holdingFlashlight = "rbxassetid://13956934376",
highSanityIdle = "rbxassetid://13956872221",
highSanityWalk = "rbxassetid://13956883194",
highSanityRun = "rbxassetid://13956877253",
midSanityIdle = "rbxassetid://13956912463",
midSanityWalk = "rbxassetid://13956916712",
lowSanityIdle = "rbxassetid://13956899990",
lowSanityWalk = "rbxassetid://13956908609",
lowSanityRun = "rbxassetid://13956904936"
}
local animationNames = {
beingRevived = "BeingRevived",
reviving = "Reviving",
downedIdle = "DownedIdle",
downedMoving = "DownedMoving",
crouchIdle = "CrouchIdle",
crouchMoving = "CrouchMoving",
crawlIdle = "CrawlIdle",
crawlMoving = "CrawlMoving",
jump = "Jump",
holdingObject = "HoldingObject",
holdingFlashlight = "HoldingFlashlight",
highSanityIdle = "HighSanityIdle",
highSanityWalk = "HighSanityWalk",
highSanityRun = "HighSanityRun",
midSanityIdle = "MidSanityIdle",
midSanityWalk = "MidSanityWalk",
midSanityRun = "MidSanityRun",
lowSanityIdle = "LowSanityIdle",
lowSanityWalk = "LowSanityWalk",
lowSanityRun = "LowSanityRun"
}
local function playAnimation(animationId, humanoid)
local track = humanoid:LoadAnimation(animationId)
track:Play()
end
local sanityValue = humanoid:GetAttribute("Sanity") or 0
local sanityChangedSignal = Instance.new("BindableEvent")
local function setSanity(value)
sanityValue = value
sanityChangedSignal:Fire(value)
end
local function getSanity()
return sanityValue
end
local function playJumpAnimation()
playAnimation(animationIds.jump, humanoid)
end
local function checkSanityAndPlayAnimation()
local currentSanity = getSanity()
if currentSanity and currentSanity >= 80 then
if humanoid.WalkSpeed == 0 then
playAnimation(animationIds.highSanityIdle, humanoid)
elseif humanoid.WalkSpeed > 5 or not humanoid:FindFirstChild("IsRunning") then
playAnimation(animationIds.highSanityWalk, humanoid)
elseif humanoid.WalkSpeed > 10 or humanoid:FindFirstChild("IsRunning") then
playAnimation(animationIds.highSanityRun, humanoid)
end
elseif currentSanity and currentSanity >= 65 then
-- Mid Sanity Animations
playAnimation(animationIds.midSanityIdle, humanoid)
elseif currentSanity and currentSanity < 65 then
-- Low Sanity Animations
playAnimation(animationIds.lowSanityIdle, humanoid)
end
end
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Freefall then
playJumpAnimation()
elseif newState == Enum.HumanoidStateType.Running or newState == Enum.HumanoidStateType.RunningNoPhysics then
checkSanityAndPlayAnimation()
end
end)
humanoid.AttributeChanged:Connect(function(attribute)
if attribute == "Sanity" then
local newSanityValue = humanoid:GetAttribute(attribute)
setSanity(newSanityValue)
end
end)
checkSanityAndPlayAnimation()
sanityChangedSignal.Event:Connect(checkSanityAndPlayAnimation)
I’ve re-done this script around 50 times, so if you think I should abolish this script too and make a new one, please let me know. Sending Animation tutorial videos can help aswell.
For context clues: My friend has made these animations and uploaded them to his account (I don’t know if that’s one reason why this script won’t work).
One of the errors is the Animations don’t work. This is a horror game and when your sanity is higher a certain walk, idle, and run animation is supposed to run for you. Same applies for the Mid and Lower sanity animations. But none of those work. I have my Sanity set as a Attribute (NumberValue) in my humanoid, but I also don’t know why if that’s one of the reasons why this script refuses to work.
Another issue is Line 52:
This is why I’m wondering if this has something to do with the animations being loaded onto my friend’s account.
Suggestions?