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

How to make sound stop when a localplayer dies?

Asked by
hokyboy 270 Moderation Voter
4 years ago

My current script that does not work

repeat wait() until game:GetService("Players").LocalPlayer
local Character = workspace:FindFirstChild(game.Players.LocalPlayer.Name) 
while wait() do
    if Character:FindFirstChild("Humanoid") then 
        if Character.Humanoid.Health.Value <= 0 then
           game.Workspace.Medium.MusicCrazy:Stop()
        end
    end
end
0
You should refrain from using a while wait() loop, that's asking for a memory spike. Something like 'while wait(0.45) do' would work here. Gojinhan 353 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

Just use the died event instead

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            game.Workspace.Medium.MusicCrazy:Stop()
        end)
    end)
end)
0
Sorry for commeting so late but where do i put the script hokyboy 270 — 4y
Ad

Answer this question