Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Certain body part triggering an event?

Asked by 3 years ago

So, I am trying to make footsteps that change upon different materials. My current script works when walking at a normal speed, but it isn't in sync with the players feet when you shift to sprint. As an alternative, I am trying to make it where everytime your left or right foot hits the ground, it will play the footstep audio. I don't really know how to make it only work when your left or right foot touches ground, how do I add that into this script (or do I need an entirely different script?):

Script 1 (what I need to change):

--|| SERVICES ||--
local RunService = game:GetService("RunService")

local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")

local Database = require(script.SoundsData)

local soundConnection
local stepInterval = 0.1
local lastStep = tick()

local Sound = Instance.new("Sound")
Sound.MaxDistance = 150
Sound.Looped = true
Sound.Name = "Material Walking Sound"
Sound.Parent = Character.HumanoidRootPart

Humanoid.Running:Connect(function(Speed)
    if Speed > 0 then
        if not Sound.IsPlaying then
            Sound:Play()
        end
    else
        Sound:Stop()
    end
end)

Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
    if Database[Humanoid.FloorMaterial] then
        Sound.SoundId = Database[Humanoid.FloorMaterial]
    end
end)

Script 2 (Modual script):

local module = {

    [Enum.Material.Grass] = "rbxassetid://1612904572",
    [Enum.Material.Concrete] = "rbxassetid://1612901699",
    [Enum.Material.Metal] = "rbxassetid://1612913774",
    [Enum.Material.DiamondPlate] = "rbxassetid://1612913774",
    [Enum.Material.Pebble] = "rbxassetid://1612906793",
    [Enum.Material.Wood] = "rbxassetid://1612936942",
    [Enum.Material.WoodPlanks] = "rbxassetid://1612936942",
    [Enum.Material.Plastic] = "rbxassetid://1612894121",
    [Enum.Material.SmoothPlastic] = "rbxassetid://1612894121",
    [Enum.Material.Sand] = "rbxassetid://1612904991",
    [Enum.Material.Brick] = "rbxassetid://1612901699",
    [Enum.Material.Cobblestone] = "rbxassetid://1612901699",
    [Enum.Material.Asphalt] = "rbxassetid://1612901699",
    [Enum.Material.Basalt] = "rbxassetid://1612901699",
    [Enum.Material.CorrodedMetal] = "rbxassetid://1612913774",
    [Enum.Material.CrackedLava] = "rbxassetid://1685241406",
    [Enum.Material.Fabric] = "rbxassetid://6240702531",
    [Enum.Material.Foil] = "rbxassetid://1685241406",
    [Enum.Material.ForceField] = "rbxassetid://1612920388",
    [Enum.Material.Glacier] = "rbxassetid://772157562",
    [Enum.Material.Glass] = "rbxassetid://4085888884",
    [Enum.Material.Granite] = "rbxassetid://1612901699",
    [Enum.Material.Ground] = "rbxassetid://977245079",
    [Enum.Material.Ice] = "rbxassetid://1685241406",
    [Enum.Material.LeafyGrass] = "rbxassetid://977245079",
    [Enum.Material.Limestone] = "rbxassetid://1612901459",
    [Enum.Material.Marble] = "rbxassetid://1612901699",
    [Enum.Material.Mud] = "rbxassetid://549000724",
    [Enum.Material.Neon] = "rbxassetid://1612901699",
    [Enum.Material.Pavement] = "rbxassetid://1612901699",
    [Enum.Material.Rock] = "rbxassetid://1612901699",
    [Enum.Material.Salt] = "rbxassetid://134456884",
    [Enum.Material.Sandstone] = "rbxassetid://1612901699",
    [Enum.Material.Slate] = "rbxassetid://1612901699",
    [Enum.Material.Snow] = "rbxassetid://1612920388",
    [Enum.Material.Water] = "rbxassetid://1612931457",
}

return module

Put script 2 inside of script 1 and put script 1 inside of StarterCharacterScripts. Thanks in advance!

0
If you like the current script you are welcome to use it, but please change the audio ID's so it's not the same as mine. 2xA_Imagineer95 0 — 3y

Answer this question