wait(1)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChild(“Humanoid”)
local animator = humanoid:WaitForChild(“Animator”)
local footsteps = require(script:WaitForChild(“Footsteps”))
local lastFootstepSound = nil
local UIS = game:GetService(“UserInputService”)
local canJump = false
local HRP = character:WaitForChild(“HumanoidRootPart”)
local direction = Vector3.new(0,1,0)
local side = “Left” and “Right”
local leg = character:FindFirstChild(side … " Leg")
local foot = leg:FindFirstChild(side … “FootAttachment”)
local jumpModule = require(script:WaitForChild(“JumpModule”))
local materialRaycast = require(script:WaitForChild(“MaterialRaycast”))
local materials = materialRaycast.materials
local animTracks = {
Walk = script:WaitForChild(“Walk”),
Run = script:WaitForChild(“Run”),
Jump = script:WaitForChild(“Jump”),
Idle = script:WaitForChild(“Idle”),
}
for Name, Object in pairs(animTracks) do
animTracks[Name] = animator:LoadAnimation(Object)
end
function StopAnims(ignoreAnim)
for i, animTrack in pairs(animator:GetPlayingAnimationTracks()) do
if animTrack.Name == ignoreAnim or ignoreAnim == “Run” and animTracks.Name == “Walk” then
continue
end
animTrack:Stop()
end
end
local function Movement()
if humanoid.FloorMaterial ~= Enum.Material.Air or humanoid.FloorMaterial ~= Enum.Material.Water then
if animTracks[“Run”].isPlaying then
animTracks[“Walk”]:Stop()
elseif animTracks[“Walk”].isPlaying then
animTracks[“Run”]:Stop()
end
if humanoid.WalkSpeed <= 9 and humanoid.MoveDirection.Magnitude > 0 then
animTracks["Run"]:Stop()
animTracks["Walk"]:Play()
elseif humanoid.WalkSpeed > 9 and humanoid.MoveDirection.Magnitude > 0 then
animTracks["Walk"]:Stop()
animTracks["Run"]:Play()
elseif humanoid.MoveDirection.Magnitude == 0 then
animTracks["Walk"]:Stop()
animTracks["Run"]:Stop()
animTracks["Idle"]:Play()
end
end
end
local function PlayFootstepSound(foot, material)
if not foot then return end
local sounds = footsteps.sounds[material]
if not sounds then return end
local random = Random.new()
local soundId = sounds[random:NextInteger(1, #sounds)]
if soundId and soundId ~= lastFootstepSound then
lastFootstepSound = soundId
local sfx = Instance.new("Sound")
sfx.SoundId = soundId
sfx.RollOffMaxDistance = 100
sfx.RollOffMinDistance = 10
sfx.Volume = footsteps.volume[material] or 0.5
sfx.Parent = foot
sfx:Play()
task.spawn(function()
sfx.Ended:Wait()
sfx:Destroy()
end)
else
PlayFootstepSound(foot, material)
end
end
local function OnFootStep(side)
local leg = character:FindFirstChild(side…" Leg")
local foot = leg:FindFirstChild(side…“FootAttachment”)
local floorMaterial = humanoid.FloorMaterial
local material = footsteps.materialMap[floorMaterial]
PlayFootstepSound(foot, material)
end
function Jump()
UIS.InputBegan:Connect(function(input, gpe)
if input.KeyCode == Enum.KeyCode.Space then
StopAnims()
animTracks[“Jump”]:Play()
wait(animTracks[“Jump”].Length + 0.1)
jumpModule.Jumping(HRP)
end
end)
end
function AnimationLoader()
animTracks[“Walk”].Priority = Enum.AnimationPriority.Movement
animTracks[“Run”].Priority = Enum.AnimationPriority.Movement
animTracks[“Jump”].Priority = Enum.AnimationPriority.Action
animTracks[“Idle”].Priority = Enum.AnimationPriority.Idle
humanoid.Running:Connect(Movement)
Jump()
animTracks["Idle"]:Play()
animTracks["Walk"]:GetMarkerReachedSignal("Footstep"):Connect(OnFootStep)
animTracks["Run"]:GetMarkerReachedSignal("Footstep"):Connect(OnFootStep)
end
AnimationLoader()
game:GetService(“RunService”).Heartbeat:Connect(function()
materialRaycast.Raycast(foot, direction)
end)