local player = game.Players.LocalPlayer repeat wait() until player:FindFirstChild("leaderstats") local lives = player.leaderstats.Respawns player.CharacterAdded:connect(function(character) character:FindFirstChild("Humanoid").Died:connect(function() wait() lives.Value = lives.Value - 1 player:FindFirstChild("Backpack").Death:Play() wait(1) children = player.Backpack:GetChildren() for _,v in pairs(children) do if v:IsA("Sound") then repeat wait() v:Stop() until v.IsPlaying == false end end end) end)
This is in a LocalScript in the Starterpack (a LocalScript will help me the best, so don't suggest a server script). It's supposed to cut off 1 life from your stats, and play a sound. It does neither of these, for some reason.
I kind of remade your script, the coding is untested, but I think it works (Sorry if didn't help, bit tired. ;-; );
repeat wait(0) until game.Players.LocalPlayer and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") and script and script.Parent and game.Players.LocalPlayer:FindFirstChild("leaderstats") and game.Players.LocalPlayer.leaderstats:FindFirstChild("Respawns") and game.Players.LocalPlayer:FindFirstChild("Death") local plr = game.Players.LocalPlayer local char = plr.Character local hum = char.Humanoid local stats = plr.leaderstats local respawns = stats.Respawns wait(0) plr.Death:Stop() --This will stop the Sound named 'Death' from looping/playing when the player respawns (Within LocalPlayer) wait(0) local function onDeath() if hum.Health <= 0 then if respawns.Value > 0 then respawns.Value = respawns.Value - 1 for i,v in pairs(plr:GetChildren()) do if v:IsA("Sound") then repeat wait(0) v:Stop() until v:Stop() or not v.IsPlaying end end plr.Death:Play() else print("Out of respawns") for i,v in pairs(plr:GetChildren()) do if v:IsA("Sound") then repeat wait(0) v:Stop() until v:Stop() or not v.IsPlaying end end plr.Death:Play() -- Rest of coding end end end; hum.Changed:connect(onDeath);
Sorry if wasn't very useful, didn't explain well, coded the code wrong, or the code didn't work, a bit tired tonight for some reason. ;-; Hope this helped!
Maybe try putting it in lighting instead. Thats what I think but im not no pro scripter.