I plan to make a Gui that Appears when a player's health is below 20, if it is over 20 the Gui will not popup
FYI: NO ERROR POPPED UP
Here is my Code:
local s=Instance.new("Sound")--created a Sound if game.Players.LocalPlayer.Character.Humanoid.Health<=20 then s.SoundId="http://www.roblox.com/asset/?id=149532107" s.Parent=workspace s.Looped=true script.Parent.Visible=true--the script.Parent is the Frame else if game.Players.LocalPlayer.Character.Humanoid.Health>=20 then script.Parent.Visible=false s.Parent=workspace s:stop() end end while true do script.Parent.BackgroundTransparency=0.2 wait(0.1) script.Parent.BackgroundTransparency=0.1 wait(0.1) script.Parent.BackgroundTransparency=0 wait(0.1) script.Parent.BackgroundTransparency=0.1 wait(0.1) script.Parent.BackgroundTransparency=0.2 wait(0.1) script.Parent.BackgroundTransparency=0.3 wait(0.1) end
*Please Reply back I would appreciate it! *
Your problem is that that if
chunk is only ever called once: when the script is first ran. You have to connect it to an Event or put it in a loop. Luckily, the HealthChanged
Event of Humanoid works for our needs!
game.Players.LocalPlayer.Character.Humanoid.HealthChanged:connect(function(health) if health <= 20 then s.SoundId = "http://www.roblox.com/asset/?id=149532107" s.Parent = workspace s.Looped = true script.Parent.Visible = true else --if health > 20 then --The if statement here is actually unnecessary, and `elseif` works in Lua. script.Parent.Visible = false s.Parent = workspace s:stop() end end)
Are you using a LocalScript? Where is this script located at? Is your hierarchy correct?
Assuming everything is good, try to use elseif
instead.
Line 8 would look like this:
elseif game.Players.LocalPlayer.Character.Humanoid.Health>=20 then