So what I am trying to do is that a gui gets enabled when the player is under a certain amount of health
what I tried:
local players = game:GetService("Players")
local player = players.LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
if hum.Health < 75 then
script.Parent.Visible = true
else
script.Parent.Visible = false
end
Hi, Your script cannot be working, because you checking player’s health only one time. I think, the best way you can check player health is event HealthChanged. That event contains really useful parametr, character currently health.
Example code (LocalScript in StarterPlayerScripts):
local plr = game:GetService("Players").LocalPlayer; -- player
local character = plr.Character or plr.CharacterAdded:Wait(); -- player's character
local humanoid = character:WaitForChild("Humanoid"); -- humanoid
local gui = plr:WaitForChild("PlayerGui"):WaitForChild("ScreenGui") -- your gui
local health = 75; -- your required health
humanoid.HealthChanged:Connect(function(currentHealth) -- function
if(currentHealth < health)then -- checking if player's health is lower than 75
gui.Enabled = true; -- if yes, gui is visible
else
gui.Enabled = false; -- if no, gui isn't visible
end
end)