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

How would I change a GUI Text when a intvalue is changed?

Asked by 5 years ago
Edited 5 years ago

I am developing a GUI that shows how many lives someone has left and changes based on that int value. Everything works fine up until it attempts to change the text. I get the print statement in the output successfully but the text of the GUI does not change. I also get no error at all in the output.

local clickSound = workspace.SoundEffects.ClickSound
local continueButton = script.Parent.Continue
local backButton = script.Parent.BackToCamp
local frame = script.Parent
local clickSound = workspace.SoundEffects.ClickSound
local HUD = script.Parent.Parent.Parent:WaitForChild("HUD")
local player = game:GetService("Players").LocalPlayer
local teleportingFrame = HUD.Parent:WaitForChild("Teleport").Background
local livesText = script.Parent.LivesRemaining.Text
local livesRemaining = game:GetService("ReplicatedStorage"):WaitForChild("ExtraLives")
local realtimelives = game:GetService("ReplicatedStorage"):WaitForChild("RealTimeLives")
local debounce = false

livesText = livesRemaining.Value.." Extra Lives"
realtimelives.Changed:Connect(function()
    if realtimelives.Value == 0 then
        print("You Died")
        script.Parent:TweenPosition(UDim2.new(0,0,0,0))
    end
end)

--this is the issue
livesRemaining.Changed:Connect(function()
    print("Changing Extra Lives")
    livesText = livesRemaining.Value
end)
--this is the issue

continueButton.MouseButton1Click:Connect(function()
    if debounce == false then
        debounce = true
        if livesRemaining.Value ~= 0 then
            closePauseMenu()
            livesRemaining.Value = livesRemaining.Value - 1
        elseif livesRemaining.Value == 0 then
            continueButton.Text = "Not Enough Extra Lives"
            wait(2)
            continueButton.Text = "Continue"
        end 
        wait()
        debounce = false
    end
end)

function closePauseMenu()
    HUD.HealthBars:TweenPosition(UDim2.new(0.7,0,0.01,0))
    HUD.Pause:TweenPosition(UDim2.new(0.006,0,0.013,0))
    frame:TweenPosition(UDim2.new(0,0,1,0))
    wait(1)
    player.Character.Humanoid.WalkSpeed = 16
    player.Character.Humanoid.JumpPower = 50
end

function teleportToCamp()
    --Insert Teleport Script Here
end

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago

You are only changing the livesText string variable inside your script, you are not actually changing script.Parent.LivesRemaining.Text

To do that, you'd have to have a reference to LivesRemaning textbox and change it's text property every time you want to change the text. It would look like this:

livesRemainingTextBox = script.Parent.LivesRemaining
livesRemainingTextBox.Text = "Lives: " .. tostring(livesRemaining.Value)

Instead of this:

livesText = livesRemaining.Value
---^^ this is only changing the variable, not the Text property!!! 

The full event would look like this:

livesRemainingTextBox = script.Parent.LivesRemaining

livesRemaining.Changed:Connect(function()
    print("Changing Extra Lives")
    livesRemainingTextBox.Text = "Lives: " .. tostring(livesRemaining.Value)
end)

0
thanks so much jakebball2014 84 — 5y
0
np common mistake royaltoe 5144 — 5y
Ad

Answer this question