Hello,
I am using a simple moving platform script.The problem is when a character stands on the moving platform that moves back and forth, the sounds of walking or footsteps can continually be heard. I need an addition to the script to prevent the walking steps sound upon standing on the platform by the character. Thanks.
platform = game.Workspace.Test6.Platform bodyposition = script.Parent.BodyPosition finish = game.Workspace.Test6.Finish start = game.Workspace.Test6.Start while true do bodyposition.Position = start.Position wait(2.3) bodyposition.Position = finish.Position wait(2.5) end
I created a fix for this a while back, but it involves several steps. I'll try to explain what you need to do as clearly as I can. The below could be simplified if all you cared about was stopping the walking sound when the player is on a moving platform, but if you still want the footstep sounds to play when the player is walking on a moving platform, and to only stop them when the player is not walking, then the code below will do what you need.
First the easy part. Copy the script below and add it StarterPlayerScripts inside StarterPlayer.
local player = game.Players.LocalPlayer local platformName = "Platform" local isOnPlatform = Instance.new("BoolValue") isOnPlatform.Name = "IsOnPlatform" isOnPlatform.Value = false isOnPlatform.Parent = player local shouldSilenceWalk = Instance.new("BoolValue") shouldSilenceWalk.Name = "ShouldSilenceWalk" shouldSilenceWalk.Value = false shouldSilenceWalk.Parent = player while wait(0.1) do local character = player.Character if character then local rootPart = character:FindFirstChild("HumanoidRootPart") if rootPart then local ray = Ray.new(rootPart.Position - Vector3.new(0, 2, 0), Vector3.new(0, -0.5, 0)) local part, position = workspace:FindPartOnRay(ray, character) if part and part.Name == platformName then player.IsOnPlatform.Value = true else player.IsOnPlatform.Value = false end end end end
The above code adds two bool values to the player that we will use to see if we want to be playing the footstep sounds or not. The while loop continually checks with a raycast to see if the player is standing on a moving platform. You will want to change the platformName variable at the top to the name of your moving platform. By default I have set it to "Platform". You can also change the wait(0.1) in the while loop to be faster or slower, depending on how regularly you want to check if the player is on the platform. The default I have set it to works well.
You are next going to have to customize the character Sound script, and the player ControlScript script. For clarity i'll spell things out step by step, so forgive me if you know some of this already. So first the Sound script.
In studio, press the play button. In the explorer, expand Workspace, and then expand your character. Copy (Ctrl+C) the Sound script you see inside your character, and then press the stop button to stop the game. Find the StarterCharacterScripts folder in StarterPlayer, and paste the Sound script into it (Ctrl+Shift+V).
If you expand the Sound script that you pasted in, you will see that it contains a local script called LocalSound. Open LocalSound and on line 197 you will see this line:
if Util.HorizontalSpeed(Head) > 0.5 then
You want to change this line to read:
if Util.HorizontalSpeed(Head) > 0.5 and not game.Players.LocalPlayer.ShouldSilenceWalk.Value then
With that we are done with the sound script, so on to ControlScript
In studio, press the play button. In the explorer, expand Players, then expand your player, then expand PlayerScripts. Copy the ControlScript that you see in there and press stop to stop the game. Find the StarterPlayerScripts folder in StarterPlayer and paste the ControlScript script into it.
If you expand the ControlScript script that you pasted in, you will see that it contains a module script called MasterControl. Open MasterControl and on line 84 you will see the updateMovement function. Within this function, on line 97, you need to paste this code:
if LocalPlayer.IsOnPlatform.Value then if moveValue:isClose(Vector3.new(), 1e-7) then LocalPlayer.ShouldSilenceWalk.Value = true else LocalPlayer.ShouldSilenceWalk.Value = false end end
So the whole updateMovement function will now look like this:
local updateMovement = function() if not areControlsEnabled then return end local humanoid = getHumanoid() if not humanoid then return end if isJumpEnabled and isJumping and not humanoid.PlatformStand then local state = humanoid:GetState() if state ~= STATE_JUMPING and state ~= STATE_FREEFALL and state ~= STATE_LANDED then humanoid.Jump = isJumping end end -- This is what you pasted in if LocalPlayer.IsOnPlatform.Value then if moveValue:isClose(Vector3.new(), 1e-7) then LocalPlayer.ShouldSilenceWalk.Value = true else LocalPlayer.ShouldSilenceWalk.Value = false end end moveFunc(LocalPlayer, moveValue, true) end
And thats it. Now ingame, if you are standing still on a moving platform with the same name as you set in the first script, then you will no longer have footstep sounds playing. If you walk around on the moving platform, you will hear footstep sounds like you would expect.
Sorry this was so long, but I hope I was clear with everything. If you have any further questions feel free to ask.