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

Hi guys so how do I stop the sound after I click when my health is 0?

ok it now says expected then when parsing if statement got '=' here code:

`local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local humanoid = player.character.humanoid

if humanoid.health = 0 then stopsound() else if humanoid.health < 0 then stopsound() end end

function playsound()

sound = Instance.new("Sound")
sound.Parent = player.Character
sound.SoundId = "rbxassetid://9815509707"
sound:Play()

end

local function stopsound()

    sound:Stop()
    sound:Destroy()
end

mouse.Button1Down:Connect(playsound)

mouse.Button1Up:Connect(stopsound) humanoid.health.changed:connect(function() end)

function playsound()

sound = Instance.new("Sound")
sound.Parent = player.Character
sound.SoundId = "rbxassetid://9815509707"
sound:Play()

end

local function stopsound()

    sound:Stop()
    sound:Destroy()
end

mouse.Button1Down:Connect(playsound)

mouse.Button1Up:Connect(stopsound) humanoid.health.changed:connect(function() end)`

3 answers

Well it looks like you never defined Humanoid... (so do it)

2 comments

0

ok i defined humanoid not work

0

local player = game:GetService("Players").LocalPlayer local mouse = player:GetMouse() local H = 0 local local Humanoid = game.LocalPlayer:FindFirstChild(Humanoid) function playsound() sound = Instance.new("Sound") sound.Parent = player.Character sound.SoundId = "rbxassetid://9815509707" sound:Play() end local function stopsound() sound:Stop() sound:Destroy() end mouse.Button1Do

add these lines

local humanoid = player.character.humanoid

humanoid.health.changed:connect(function()
if humanoid.health = 0 then
stopsound()
else if humanoid.health < 0 then
stopsound()
end)
end)

6 comments

0

still doesnt work

0

made a error try this humanoid.health,changed:connect:function()

0

look at my answer again

0

expected then 'then' when parsing if statement got '='

0

also I only want it to be client btw

0

at if humanoid.health = 0 change it to if humanoid.health == 0 then

You have to put "==" instead of "=" in the line with the if and else if statements, also you dont need two statements i think

So it would be this

if humanoid.health <= 0 then
 stopsound() 
end

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