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 ?
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)
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