Hello! So i made a Momentum script for my character in my 3D platformer, but i found out that the footstep sound doesn’t sync with the speed of the character. I looked for solutions till i found GetMarkerReachedSignal.
I managed to make it work, i added the markers into both the Walking and Running animations, and i named them “Step”. Now for some reason the code doesn’t work, there is no error in the output, i have made sure that i added the markers and got their names correct, i even reuploaded the animations, but still to no avail.
I have added a print()
to the function but it doesn’t print anything. I think it has something to do with how i defined the animations, but again, i’m not sure.
Here’s the code :
--//Services//--
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
--//Variables//--
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animate = Character:WaitForChild("Animate")
local Walk = Animate.walk
local Run = Animate.run
local Root = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Head = Character:WaitForChild("Head")
local Face = Head.Face
local Landing = script:WaitForChild("Landing")
local LandingAnim = Humanoid:LoadAnimation(Landing)
local LandingSound = Root:WaitForChild("ND_Land")
local LeftFoot = Character:WaitForChild("LeftFoot")
local RightFoot = Character:WaitForChild("RightFoot")
local Footstep = Root:WaitForChild("ND_Step")
local Impact1 = Root:WaitForChild("ND_Thump1")
local Impact2 = Root:WaitForChild("ND_Thump2")
local ImpactSounds = {Impact1, Impact2}
local HitFloor1 = script:WaitForChild("HitFloor1")
local HF1Anim = Humanoid:LoadAnimation(HitFloor1)
local WalkAnim = Humanoid:LoadAnimation(Walk.WalkAnim)
local RunAnim = Humanoid:LoadAnimation(Run.RunAnim)
--//Functions//--
------------------------------------------------------
local function onWalkOrRunPlayed()
print("step")
Footstep:Play()
end
------------------------------------------------------
local function onHumanoidRunning(Speed)
if Speed > 6 then
local DustPart1 = Instance.new("Part", LeftFoot)
local Mesh1 = Instance.new("SpecialMesh", DustPart1)
Mesh1.MeshId = "rbxassetid://13977814347"
Mesh1.Scale = Vector3.new(0.04, 0.04, 0.04)
DustPart1.Name = "DP1"
DustPart1.Size = Vector3.new(0.75, 0.5, 0.75)
DustPart1.Position = LeftFoot.Position
DustPart1.BrickColor = BrickColor.new(255, 255, 255)
DustPart1.CanCollide = false
DustPart1.CanTouch = false
DustPart1.Anchored = true
----------------------------------------------------
local DustPart2 = Instance.new("Part", RightFoot)
local Mesh2 = Instance.new("SpecialMesh", DustPart2)
Mesh2.MeshId = "rbxassetid://13977814347"
Mesh2.Scale = Vector3.new(0.04, 0.04, 0.04)
DustPart2.Name = "DP2"
DustPart2.Size = Vector3.new(0.75, 0.5, 0.75)
DustPart2.Position = RightFoot.Position
DustPart2.BrickColor = BrickColor.new(255, 255, 255)
DustPart2.CanCollide = false
DustPart2.CanTouch = false
DustPart2.Anchored = true
----------------------------------------------------
DustPart1:Clone()
DustPart2:Clone()
local TweenInform = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local TweenTransparency1 = TweenService:Create(DustPart1, TweenInform, {Transparency = 1})
local TweenSize1 = TweenService:Create(Mesh1, TweenInform, {Scale = Vector3.new(0.08, 0.08, 0.08)})
local TweenTransparency2 = TweenService:Create(DustPart2, TweenInform, {Transparency = 1})
local TweenSize2 = TweenService:Create(Mesh2, TweenInform, {Scale = Vector3.new(0.08, 0.08, 0.08)})
TweenSize1:Play()
TweenTransparency1:Play()
TweenSize2:Play()
TweenTransparency2:Play()
task.wait(0.5)
DustPart1:Destroy()
DustPart2:Destroy()
end
end
----------------------------------------------------------
local function onLandedNormal(_, State)
if State == Enum.HumanoidStateType.Landed then
LandingAnim:Play()
LandingAnim:AdjustSpeed(1.5)
LandingSound.PlaybackSpeed = math.random(10,12)/10
LandingSound:Play()
---------------------------------------------------
local CloudPart = Instance.new("Part", Character)
CloudPart.Anchored = true
CloudPart.CanCollide = false
CloudPart.CanTouch = false
CloudPart.Position = Root.Position - Vector3.new(0, 2.5, 0)
CloudPart.Size = Vector3.new(2.5, 2.5, 2.5)
CloudPart.Material = Enum.Material.Neon
CloudPart.BrickColor = BrickColor.new(255, 255, 255)
--------------------------------------------------------
local CloudMesh = Instance.new("SpecialMesh", CloudPart)
CloudMesh.Scale = Vector3.new(0.05, 0.025, 0.05)
CloudMesh.MeshId = "rbxassetid://11978515144"
--------------------------------------------------------
local TweenService = game:GetService("TweenService")
local TweenInfo1 = TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local TweenSize = TweenService:Create(CloudMesh, TweenInfo1, {Scale = Vector3.new(0.15, 0.025, 0.15)})
local TweenTransparency = TweenService:Create(CloudPart, TweenInfo1, {Transparency = 1})
TweenSize:Play()
TweenTransparency:Play()
task.wait(0.3)
CloudPart:Destroy()
end
end
-----------------------------------------------------
HF1Anim.Priority = Enum.AnimationPriority.Action4
local function onLandedDamage(_, State)
-----------------------------------------------------
if State == Enum.HumanoidStateType.Landed then
local Height = -Root.Velocity.Y
-----------------------------------------------------
if Height >= 150 then
local Damage = (Height / 80) ^ 4.5
local RandomSound = ImpactSounds[math.random(1, #ImpactSounds)]
RandomSound:Play()
Humanoid:TakeDamage(Damage)
HF1Anim:Play()
HF1Anim:AdjustSpeed(0.2)
Humanoid.WalkSpeed = 0
Humanoid.JumpPower = 0
Face.Texture = "rbxassetid://14179652797"
task.wait(1.5)
Humanoid.WalkSpeed = 26
Humanoid.JumpPower = 50
Face.Texture = "rbxassetid://14179652498"
end
end
end
---------------------------------------------------------------
local function onHumanoidNotRunning()
Footstep.Playing = false
local DustPart1 = LeftFoot:WaitForChild("DP1", math.huge)
local DustPart2 = LeftFoot:WaitForChild("DP2", math.huge)
DustPart1:Destroy()
DustPart2:Destroy()
end
---------------------------------------------------------------
--//Connections//--
Humanoid.Running:Connect(onHumanoidRunning)
Humanoid.Jumping:Connect(onHumanoidNotRunning)
Humanoid.FreeFalling:Connect(onHumanoidNotRunning)
Humanoid.Swimming:Connect(onHumanoidNotRunning)
Humanoid.Climbing:Connect(onHumanoidNotRunning)
Humanoid.StateChanged:Connect(onLandedNormal)
Humanoid.StateChanged:Connect(onLandedDamage)
WalkAnim:GetMarkerReachedSignal("Step"):Connect(onWalkOrRunPlayed)
RunAnim:GetMarkerReachedSignal("Step"):Connect(onWalkOrRunPlayed)