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!
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)
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.
Try this:
```local plr = game.Players.LocalPlayer
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)```
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