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

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

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 .

1 comment

0

You are using Starter Gui instead of Player Gui

2 answers

"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.

3 comments

0

You're still wrong dude :/ You cannot access playergui from a server script, you should clone and destroy, not enable or disable

0

That was my first thought, and then i saw the Wiki post on ScreenGuis. My bad.

0

still doesn't work.

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.

1 comment

0

Line 5 cut off. It's :FireClient(plr)

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