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

Script to show TextLabel doesn't show when player dies, any help ?

Asked by 5 years ago

so i put the following script in the Textlabel...

Player = script.Parent.Parent.Parent.Parent.Character.Humanoid

while true do

if Player.Health == 0 then
script.Parent.Visible = true
end
wait(1)
end


...so when the player dies, this scipt will make his parent textLabel to be visible, but it doesn't. Can anyone fix the problem ?

3 answers

Log in to vote
0
Answered by 5 years ago

you should use LocalPlayer of game.Players to get the player instead of indexing the player through PlayerGui. also use the Died event and use local variables as it doesn't make sense as its on the highest scope. and indent your code so its easier to read.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

character:WaitForChild("Humanoid").Died:Connect(function()
    script.Parent.Visible = true
end)
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Died Event


A simpler way to do this is by using a humanoid.Died event. the Died event of the humanoid fires when the health reaches 0, and anything below it can run, unlike an infinite loop.

It can be accessed as such

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

hum.Died:Connect(function()
    script.Parent.Visible = true
end)

Another bad practice is using script.Parent.Parent.Parent... in a local script to reference the player, when the use of game.Players.LocalPlayer is available for use.

Hopefully this helped sort out your problem

0
The Gui still doesn't show Cioss_Team 14 — 5y
0
^^^^ your suppose to do that lol xd User#23365 30 — 5y
Log in to vote
0
Answered by 5 years ago

The Gui still doesn't show

Answer this question