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

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

Asked by 1 year ago
Edited 1 year ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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

Log in to vote
0
Answered by
boredlake 256 Moderation Voter
1 year ago

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

0
ok i defined humanoid not work Pro_beatz 36 — 1y
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 Pro_beatz 36 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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)
0
still doesnt work Pro_beatz 36 — 1y
0
made a error try this humanoid.health,changed:connect:function() Not_prototype 50 — 1y
0
look at my answer again Not_prototype 50 — 1y
0
expected then 'then' when parsing if statement got '=' Pro_beatz 36 — 1y
View all comments (2 more)
0
also I only want it to be client btw Pro_beatz 36 — 1y
0
at if humanoid.health = 0 change it to if humanoid.health == 0 then Not_prototype 50 — 1y
Log in to vote
0
Answered by 1 year ago

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

Answer this question