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
5 years ago

My current script that does not work

1repeat wait() until game:GetService("Players").LocalPlayer
2local Character = workspace:FindFirstChild(game.Players.LocalPlayer.Name)
3while wait() do
4    if Character:FindFirstChild("Humanoid") then
5        if Character.Humanoid.Health.Value <= 0 then
6           game.Workspace.Medium.MusicCrazy:Stop()
7        end
8    end
9end
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 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

Just use the died event instead

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

Answer this question