Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make sound stop when a localplayer dies?

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

1 comment

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.

1 answer

✓ Accepted answer

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)

1 comment

0

Sorry for commeting so late but where do i put the script

This discussion is preserved as it was. New answers, comments, and votes are closed.