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

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

Asked by 4 years ago
Edited 4 years ago

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!

0
Cool FailyPal 0 — 4y

4 answers

Log in to vote
0
Answered by 4 years ago

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)
0
There are no errors but your script doesn't work, I have it inside of screenGUI and it's a local script. astonplep 32 — 4y
0
I think I may have done something wrong hold on.... astonplep 32 — 4y
0
welp I Ended up cdoing this AmazingAmazingArthur 15 — 4y
0
oh ok. AmazingAmazingArthur 15 — 4y
View all comments (2 more)
0
This code doesn't go back and change the text once the player dies Accuide 0 — 4y
0
Try my code below? Accuide 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
It's isn't working, but no errors. astonplep 32 — 4y
0
Can I see where the script is placed in relation to the textlabel, etc. Accuide 0 — 4y
0
ok hold on.... astonplep 32 — 4y
0
Hold up. I spelled character wrong Accuide 0 — 4y
View all comments (2 more)
0
go to the chat astonplep 32 — 4y
0
this is not working...... astonplep 32 — 4y
Log in to vote
0
Answered by 4 years ago

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

0
not working.. astonplep 32 — 4y
Log in to vote
0
Answered by 4 years ago
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

Answer this question