Hey guys, I'm pretty new to Lua and I'm having some difficulty figuring out how I'm supposed to do this. As the title states, I'm trying to do some kind of loop that checks what the player is standing on and then changes the footstep sounds.
This is my initial code, which is not really working as intended. Once I step on the snow the sound doesn't loop and plays a million times at the same time.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local isWalking = false
player.Character.Sound:Destroy()
for i,object in pairs(player.Character.Head:getChildren()) do
if object:IsA("Sound") then
object:Destroy()
end
end
local footsteps = Instance.new("Sound", character.Head)
footsteps.SoundId = "http://www.roblox.com/asset/?id=619083295"
footsteps.Volume = 1
footsteps.Pitch = 1
footsteps.Looped = true
player.Character.Humanoid.Running:connect(function(speed)
if speed > 7 then
isWalking = true
else
isWalking = false
end
end)
while true do
wait()
if character.Humanoid.FloorMaterial == Enum.Material.Snow and isWalking then
footsteps:Play()
else
footsteps:Stop()
end
end
I tried messing around with it and I replaced the last part with this:
while true do
wait()
if character.Humanoid.FloorMaterial ~= nil then
print(character.Humanoid.FloorMaterial.Name)
end
end
Which does read what I'm standing on but I'm not sure how to apply it to what I'm trying to do.
I also tried this but it's not working either:
while true do
wait()
if character.Humanoid.FloorMaterial ~= nil then
if character.Humanoid.FloorMaterial.Name == "Snow" and isWalking then
footsteps:Play()
else
footsteps:Stop()
end
end
end
I'd appreciate any tips you guys could give me. Thank you
Edit: This is what I'm trying to achieve: https://www.youtube.com/watch?v=pbiGbEfiIcQ

2 comments
https://www.youtube.com/watch?v=qdhaRcmJGQ4&feature=youtu.be
Doesn't work, but I'll take your stuff and try to mess around with it until it works. One thing I'd mention is on line 39, I've read that Enum.Material.Snow would work better