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

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

Asked by
PPJASK 19
3 years ago

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

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 MrBarfSquirrel 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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

Ad

Answer this question