Text Label can't Update

I am having problems with updating the text after somebody has bought the like the stage. PStage is just the stage they are in. Payment is how much they pay. Coins is the amount of coins they have. and Price is the text label that is meant to update but doesn’t

local Price = script.Parent
local player = game.Players.LocalPlayer
local PStage = player.notleader.StageLevel
local Payment = math.round((PStage.Value *1.2)+ 500)
local Coins = player.leaderstats.Coins


if PStage.Value == 1 then
	Price.Text = "Buy For " .. Payment
end

Coins.Changed:connect(function()
		Price.Text = "Buy For " .. Payment
end)

You never update the Payment variable, did you mean to do this?

local Price = script.Parent
local player = game.Players.LocalPlayer
local PStage = player.notleader.StageLevel
local Payment = math.round((PStage.Value *1.2)+ 500)
local Coins = player.leaderstats.Coins


if PStage.Value == 1 then
	Price.Text = "Buy For " .. Payment
end

Coins.Changed:connect(function()
	Payment = math.round((PStage.Value *1.2)+ 500)
	Price.Text = "Buy For " .. Payment
end)

Not sure if you want it to check the value of the coins instead of Pstage in the changed event, nor am I sure if you meant to do PStage.Changed instead of Coins.Changed

Since you have an if statement by itself, it will run at the start of the game or when the players joins. Unless the PSValue is already assigned before this script runs it should be fine. However I would just recommend waiting for the PStage.Value to update first, then let this script run.

Well in order to get to another stage you need to use coins and the “Price” is just meant to show how many you need

Then you probably need to do this

local Price = script.Parent
local player = game.Players.LocalPlayer
local PStage = player.notleader.StageLevel
local Payment = math.round((PStage.Value *1.2)+ 500)
local Coins = player.leaderstats.Coins

Price.Text = "Buy For " .. Payment

PStage.Changed:Connect(function(newVal)
	Payment = math.round((newVal *1.2)+ 500)
	Price.Text = "Buy For " .. Payment
end)

So when the stage changes for them, it updates the text

1 Like