What do you want to achieve? stop sound playing whenever you die
What is the issue? I’m not sure how to script that
What solutions have you tried so far? I’ve tried adding stuff to the scripts but didn’t work
local player = game.Players.LocalPlayer
local character = script.Parent
local humanoid = character:FindFirstChild("Humanoid")
local sound = player.PlayerGui:FindFirstChild("LowHealthSound")
while wait() do
if humanoid.Health <= 20 then
if sound.Playing == false then
sound:Play()
end
else
if sound.Playing == true then
sound:Stop()
end
end
end
PlayerGui is a place for player’s UI objects: frames, buttons, etc. Sound should be in ReplicatedStorage. Character is a child of workspace, so you can connect to char by this line
local player = game.Players.LocalPlayer
local character = player.Character
Then you need to get your sound
local RS = game:GetService("ReplicatedStorage")
local sound = RS:FindFirstChild("LowHealthSound")
And then you can play it and stop in function binded to humanoid.Died event.
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local sound = RS:WaitForChild("OOT LowHealth")
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
sound.Parent = player.Character
humanoid.HealthChanged:Connect(function()
if humanoid.Health <= 20 then
if sound.Playing == false then
sound.Looped = true
sound:Play()
end
else
if sound.Playing == true then
sound:Stop()
end
end
end)
humanoid.Died:Connect(function()
sound:Stop()
end)
But you need to put sound in ReplicatedStorage
And change sound name in RS:WaitForChild(“OOT LowHealth”)