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

Help with how to make this the text in this GUI change?

I am making a GUI which displays "lives: 3" I want this number to deplete every time the player dies, and either kick or teleport the player somewhere else.

PS- I don't what the code looks like I just want it to work.... I've working on this for days...

this is my code so far from code I have salvaged

local hum = nil
local Lives = script.Parent.Lives

repeat
	wait()
	hum = script.Parent:FindFirstChild("Humanoid")
until hum ~= nil

hum.Died:connect(function()
	Lives.Text = ("lives: 2")
	
	
end)

If you guys could tell me how to fix this or a better way to do this that would be great!

1 comment

0

Cool

4 answers

You wanna make a IntValue And Name It Lives And Set The Value To 3 Then Use The Code Below. Pic Example: https://gyazo.com/566f7bc94df4508652c5696dbc4371d8 Pic Example2: https://gyazo.com/da40155318d06e23782034c8841c956c Comment If You Still Need Help.

local hum = nil

local LivesLabel = script.Parent.Lives

local Livesval = game.Workspace.Lives

LivesLabel.Text = "Lives: "..Livesval.Value --Setting The Amount Of Lives Left In The Value.

repeat
	wait()
	hum = script.Parent:FindFirstChild("Humanoid")
until hum ~= nil

hum.Died:connect(function()
	Livesval.Value = -1
end)

6 comments

0

There are no errors but your script doesn't work, I have it inside of screenGUI and it's a local script.

0

I think I may have done something wrong hold on....

0

welp I Ended up cdoing this

0

oh ok.

0

This code doesn't go back and change the text once the player dies

0

Try my code below?

I think you have to main ideas down there. To get it to work, you would need to define the actual humanoid. The repeat until loop is a bit unneccessary, and I don't really see the need. In addition, I think it can be accomplished through the WaitForChild() function.

In addition, I would create a variable or IntValue to see how many lives are left, so it would generally go like this, which I am assuming is in a local script under the TextLabel for lives.


local lives = 3 -- Counter of lives left. We will change this later.
local textLabelText = script.Parent.Text-- Gets the property of the TextLabel we are changing.

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
textLabelText = "Lives:" .. tostring(lives) -- The two dots combines the two segments. Tostring changes the number we have to a string.
lives = lives - 1 -- Depletes one life for next time.
end)


I haven't tested this out, but the general direction is there.

6 comments

0

It's isn't working, but no errors.

0

Can I see where the script is placed in relation to the textlabel, etc.

0

ok hold on....

0

Hold up. I spelled character wrong

0

go to the chat

0

this is not working......

Try this:

local hum = plr.Character:WaitForChild("Humanoid") 
local LivesLabel = script.Parent.Lives	 
local Livesval = game.Workspace.Lives

Livesval.Changed:Connect(function() --changing the gui text everytime the value changes
	LivesLabel.Text = "Lives: "..Livesval.Value --Setting The Amount Of Lives Left In The Value.
end)
 
hum.Died:Connect(function() 
  Livesval.Value = -1
end)```

1 comment

0

not working..

local hum = nil
	local Lives = script.Parent.Lives
	 
	repeat
	    wait()
	    hum = script.Parent:FindFirstChild("Humanoid")
	until hum ~= nil
	 
	hum.Changed:connect(function()
	    if hum.Health == 0 then
 
	    	Lives.Text = ("lives: 2")
	    end
	 
	end)

Do this, also subtract from the Text value

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