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

How to make if npc health = 0, then gui appear ?

How to make if npc health = 0, then gui visible = true npc = game.Workspace.NPC gui = game.StarterGui.ScreenGui.Frame -Thank you and best regards

1 comment

0

if your gui doesn't show up, type (for _, plr in pairs(game.Players:GetPlayers()) do plr.PlayerGui.ScreenGui.Frame.Visible = true end) REMOVE THE BRACKETS

1 answer

You would write it how you explained it, except switch the variables to the top otherwise we won't know what the NPC. And it is better to access playerGui rather than StarterGui

Here is your script:

if npc.Health = 0 then
	gui.Visible = true
end

npc = game.Workspace.NPC
gui = game.StarterGui.Screengui.Frame

Revised script:

local npc = game.Workspace.NPC -- better to use local the whole time unless you need to use global
local gui = player.PlayerGui.Screengui.Frame --[[ better to locate the playergui, or put this script in the gui and classify upwards
local gui = script.Parent.Parent.Frame]]
local humanoid = npc:WaitForChild("Humanoid") -- humanoid can access health, not the model NPC

humanoid.Died:Connect(function() -- Died event is better than an if statement
	wait(0.5) -- you can remove this :)
	gui.Visible = true
end)

Here are some links if you're confused about my comments: Variables PlayerGui Humanoid.Died Event

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