Okay so here is my footstep sound code (obviously another script adds the sounds to the head when the player loads in)
local plrs = game:GetService("Players")
plrs.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
local sounds = char:WaitForChild("Head")
local humrundb = false
local walkspeed = 0
local cancel = false
humanoid.Died:Connect(function()
cancel = true
end)
local currentmaterial = nil
humanoid.Running:Connect(function(speed)
walkspeed = speed
end)
while task.wait() do
if cancel == true then
break
end
if not plr:IsDescendantOf(plrs) then
break
end
pcall(function()
if walkspeed > 7 and plr:WaitForChild("disablesteps").Value <= 0 then
print(plr.Name.." speed: "..tostring(walkspeed))
if humanoid.FloorMaterial ~= Enum.Material.Air then
if currentmaterial ~= nil then
if currentmaterial ~= humanoid.FloorMaterial then
task.wait(.1)
currentmaterial = humanoid.FloorMaterial
for i,v in pairs(sounds:GetChildren()) do
if v:IsA("Sound") then
if v.Name ~= tostring(currentmaterial):split(".")[3] then
v:Stop()
else
v.PlaybackSpeed = walkspeed/20
v:Play()
end
end
end
elseif currentmaterial == humanoid.FloorMaterial then
for i,v in pairs(sounds:GetChildren()) do
if v:IsA("Sound") then
if v.Name == tostring(currentmaterial):split(".")[3] then
v.PlaybackSpeed = walkspeed/20
end
end
end
end
elseif currentmaterial == nil then
currentmaterial = humanoid.FloorMaterial
for i,v in pairs(sounds:GetChildren()) do
if v:IsA("Sound") then
if v.Name == tostring(currentmaterial):split(".")[3] then
v.PlaybackSpeed = walkspeed/20
v:Play()
end
end
end
end
elseif humanoid.FloorMaterial == Enum.Material.Air then
for i,v in pairs(sounds:GetChildren()) do
if v:IsA("Sound") then
currentmaterial = nil
v:Stop()
end
end
end
elseif currentmaterial ~= nil then
for i,v in pairs(sounds:GetChildren()) do
if v:IsA("Sound") then
currentmaterial = nil
v:Stop()
end
end
end
end)
end
end)
end)
Now my problem is when I run a play test.
If player1 starts walking it functions
if player2 starts walking it functions
however when player1 (who loaded before player2) walks the footstep sounds play normally HOWEVER the sounds also play for player2 but it considers his walkspeed very fast even if hes standing still while player1 is moving around. Why is this and how can I fix it its very frustrating and I’ve been struggling with this for a while. I just cant seem to tell whats wrong and whats causing this error.