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

how can i change text in a gui when the player dies?

Asked by 6 years ago

hi, i made a screengui and put it in startergui, so now i need to have the text in the gui change when the player dies. the text starts as 25 so when the player dies i need the text to change to 24 and then when they die again it changes to 23 and so on. also when the text reaches 1 it sets their currency (Stage) to 1 and sets the text back to 25.

this is a script i though could be a start (its a child of the Lives gui)

game.Players.LocalPlayer.Humanoid.Health = 0
script.Parent.TextLabel.Text = 24
 end
game.Players.LocalPlayer.Humanoid.Health = 0 and
script.Parent.TextLabel.Text = 24 then do
    script.Parent.TextLabel.Text = 23

3 answers

Log in to vote
0
Answered by 6 years ago

There’s an event on the humanoid called Died. It runs every time the player dies. You can use that so the text changes every time the player dies.

Here’s a link to it if you want to learn more about it :

http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Died

I’d make an example script but I can’t because I’m on mobile.

Ad
Log in to vote
0
Answered by 6 years ago

Disable the "ResetOnSpawn" value that is in the "ScreenGUI" properties.

Then you can do this:

local Player = game.Players.LocalPlayer

local Number = 25

function Update()
local StringNumber = tostring(Number)
script.Parent.TextLabel.Text = StringNumber
end

Player.CharacterAdded:connect(function(Character)
Character:WaitForChild("Humanoid").Died:connect(function()
if Number < 2 then
Number = 25
Update()
else
Number = Number -1
Update()
end
end)
end)

0
it works, but how can i make it so it sets the players Stage value to 1? poopypigeon245 22 — 6y
0
What do you mean? Ashley_Phantom 372 — 6y
0
so when the number reaches 1, it sets all currencies to their original value, also it only works in studio poopypigeon245 22 — 6y
Log in to vote
0
Answered by 6 years ago

You could use the humanoid.Died function. I'll give an example here:

game.Players.LocalPlayer.Character.humanoid.Died:connect(function()
--YOUR GUI SCRIPT HERE
end)

When the player dies, the script in the block will run.

Answer this question