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

Whats wrong with this if health, display gui? [not working]

Asked by 6 years ago
Edited 6 years ago
if workspace.CreatureA.Humanoid.Health == 0 then
game.StarterGui.ScreenGui.Enabled = true  
end

I tried making a script that displays a gui when creatureA's health is zero but it didn't work

note: In the actual code all capital letters and spaces were correct .

0
You are using Starter Gui instead of Player Gui AlenK1 3 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

"workspace" is deprecated. You should also use PlayerGui. Your modified script:

if game.Workspace:FindFirstChild("CreatureA") ~= nil then
    model = game.Workspace:FindFirstChid("CreatureA")
    if model:FindFirstChild("Humanoid") ~= nil then
        aliveobject = model:FindFirstChild("Humanoid")
        if aliveobject.Health == 0 then
            game.Players.LocalPlayer.PlayerGui.ScreenGui:Clone().Parent = game.StarterGui
        end
    end
end

If you have any questions, please ask.

0
You're still wrong dude :/ You cannot access playergui from a server script, you should clone and destroy, not enable or disable User#20388 0 — 6y
0
That was my first thought, and then i saw the Wiki post on ScreenGuis. My bad. DeceptiveCaster 3761 — 6y
0
still doesn't work. khubzeater 0 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Use a remote event to fire to the client.

-- Local Script which clones the gui to the player.

local gui = game:GetService("ReplicatedStorage").Gui -- Put in Replicatedstorage. not serverstorage. many people get this wrong.

local showGui = Instance.new("RemoteEvent",gui.Parent)
showGui.Name = "ShowGui"
local plr = game:GetService("Players").LocalPlayer

showGui.OnClientEvent:Connect(function()
    if not plr.PlayerGui:FindFirstChild(gui.Name) then -- So their PlayerGui doesn't overflow
        gui:Clone().Parent = plr.PlayerGui
        gui.Enabled = true
    end
end)

now to fire to client

-- Server Script
if Humanoid.Health == 0 then
    local players = game:GetService("Players")
    local plr = players[Humanoid.Parent.Name]
    game:GetService("ReplicatedStorage"):WaitForChild("ShowGui"):FireClient(plr)
end

Bonus, it works for FE. You're welcome.

0
Line 5 cut off. It's :FireClient(plr) User#19524 175 — 6y

Answer this question