Self explanatory, I am trying to make a script that adjusts the animation speed relative to walkspeed. This is for my 8 directional walk system, here’s my attempt:
if NewSpeed < 18 then -- this is just a condition
local Walk = Animate:FindFirstChild("walk")
local WalkAnim = Walk.WalkAnim
if Walk and WalkAnim.AnimationId ~= "rbxassetid://12603582942" then
WalkAnim.AnimationId = "rbxassetid://12603582942"
ChangedAnimation = true
end
if ChangedAnimation == true then
local Walk = Humanoid.Animator:LoadAnimation(WalkAnim)
Walk:AdjustSpeed(Speed/16)
end
end
This is the full script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local ExtraFunctions = require(ReplicatedStorage.Modules.ExtraFunctions)
local MathAddons = require(ReplicatedStorage.Modules.MathAddons)
local LocalPlayer = Players.LocalPlayer
if not LocalPlayer then
Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
LocalPlayer = Players.LocalPlayer
end
local PlayerScripts = ExtraFunctions:WaitForChildWhichIsA(LocalPlayer, "PlayerScripts") :: PlayerScripts
local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule")) :: any
local Controls = PlayerModule:GetControls()
local Humanoid: Humanoid?
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local PlayerAnimations = ReplicatedStorage.Animations.PlayerAnimations
local LoadedAnimations = {}
local WalkAnimations = {
Back = PlayerAnimations.WalkBack;
Front = PlayerAnimations.WalkFront;
}
local Directions = {
[Vector3.new(0, 0, 0)] = "Not Moving";
[Vector3.new(0, 0, -1)] = "Foward";
[Vector3.new(0, 0, 1)] = "Backward";
[Vector3.new(-1, 0, 0)] = "Left";
[Vector3.new(1, 0, 0)] = "Right";
[Vector3.new(-1, 0, -1)] = "FowardLeft";
[Vector3.new(1, 0, -1)] = "FowardRight";
[Vector3.new(-1, 0, 1)] = "BackwardLeft";
[Vector3.new(1, 0, 1)] = "BackwardRight";
}
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Camera = workspace.CurrentCamera
local function ThumbstickCurve(X: number): number
local K_CURVATURE = 2.0
local K_DEADZONE = 0.15
local function FCurve(X: number): number
return (math.exp(K_CURVATURE * X) - 1) / (math.exp(K_CURVATURE) - 1)
end
local function FDeadzone(X: number): number
return FCurve((X - K_DEADZONE) / (1 - K_DEADZONE))
end
return math.sign(X) * math.clamp(FDeadzone(math.abs(X)), 0, 1)
end
Humanoid.Running:Connect(function(Speed)
local Animate = Character:FindFirstChild("Animate")
local MoveVector = Controls:GetMoveVector()
MoveVector = Vector3.new(
math.round(ThumbstickCurve(MoveVector.X)),
math.round(ThumbstickCurve(MoveVector.Y)),
math.round(ThumbstickCurve(MoveVector.Z))
)
local NewSpeed = math.round(Speed)
local ChangedAnimation = false
-- This right here is my attempt
if NewSpeed < 18 then -- this is just a condition
local Walk = Animate:FindFirstChild("walk")
local WalkAnim = Walk.WalkAnim
if Walk and WalkAnim.AnimationId ~= "rbxassetid://12603582942" then
WalkAnim.AnimationId = "rbxassetid://12603582942"
ChangedAnimation = true
end
if ChangedAnimation == true then
local Walk = Humanoid.Animator:LoadAnimation(WalkAnim)
Walk:AdjustSpeed(Speed/16)
end
end
--if Directions[MoveVector] == "Foward" then
-- local Walk = Animate:FindFirstChild("walk")
-- local WalkAnim = Walk.WalkAnim
-- if Walk and WalkAnim.AnimationId ~= "rbxassetid://12603582942" then
-- print(MoveVector," | ", Directions[MoveVector])
-- WalkAnim.AnimationId = "rbxassetid://12603582942"
-- end
--end
--if Directions[MoveVector] == "Backward" then
-- local Walk = Animate:FindFirstChild("walk")
-- local WalkAnim = Walk.WalkAnim
-- if Walk and WalkAnim.AnimationId ~= "rbxassetid://12603582942" then
-- print(MoveVector," | ", Directions[MoveVector])
-- WalkAnim.AnimationId = "rbxassetid://12603582942"
-- end
--end
end)