Cant change text

so i have this script:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Prices = Player:WaitForChild("Prices")
local Upgrades = Player:WaitForChild("Upgrades")
local WalkSpeedUpgradePrice = Prices.WalkSpeedUpgradePrice
local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade

local Abbreviations = {"", "K", "M", "B", "T", "Qa", "Qi",}

local function Format(value, decimals)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = Abbreviations [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ decimals) / (1000 ^ ex))) / (10 ^ decimals)

	return ("%."..decimals.."f%s"):format(normal, abbrevs)
end

local function UpdateText(newValue)
	local FormattedText = Format(newValue, 2)

	script.Parent.Text = FormattedText
end

UpdateText(WalkSpeedUpgradePrice.Value)
WalkSpeedUpgradePrice.Changed:Connect(UpdateText)

and i want to make text says “MAX” when player WalkSpeedUpgrade = 5
i tried many ways but it doesn’t work

yes i tried if statement it doesn’t work

try make this
this:

local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade.Value

1 Like

it’s just variable that i keep when trying to do

if WalkSpeedUpgrade.Value >= 5 then
UpdateText("MAX")
end

Try setting .Value after the

at the top

not in the if statement.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Prices = Player:WaitForChild("Prices")
local Upgrades = Player:WaitForChild("Upgrades")
local WalkSpeedUpgradePrice = Prices.WalkSpeedUpgradePrice
local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade.Value

local Abbreviations = {"", "K", "M", "B", "T", "Qa", "Qi",}

local function Format(value, decimals)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = Abbreviations [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ decimals) / (1000 ^ ex))) / (10 ^ decimals)

	return ("%."..decimals.."f%s"):format(normal, abbrevs)
end

local function UpdateText(newValue)
	local FormattedText = Format(newValue, 2)

	script.Parent.Text = FormattedText
end

if WalkSpeedUpgrade <= 5 then
UpdateText(WalkSpeedUpgradePrice.Value)
WalkSpeedUpgradePrice.Changed:Connect(UpdateText)
else
	UpdateText("MAX")
end

like that? didn’t work tho

Maybe try this

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Prices = Player:WaitForChild("Prices")
local Upgrades = Player:WaitForChild("Upgrades")
local WalkSpeedUpgradePrice = Prices.WalkSpeedUpgradePrice
local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade.Value

local Abbreviations = {"", "K", "M", "B", "T", "Qa", "Qi",}

local function Format(value, decimals)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = Abbreviations [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ decimals) / (1000 ^ ex))) / (10 ^ decimals)

	return ("%."..decimals.."f%s"):format(normal, abbrevs)
end

local function UpdateText(newValue)
	local FormattedText = Format(newValue, 2)

	script.Parent.Text = FormattedText
end

While true do
wait(1)
if WalkSpeedUpgrade <= 5 then
UpdateText(WalkSpeedUpgradePrice.Value)
WalkSpeedUpgradePrice.Changed:Connect(UpdateText)
else
	UpdateText("MAX")
end
end

What this does it it checks ever 1 seconds if the player has less then 5 speedupgrades and if not it sets the text to “MAX”.

still no as i said i tried many ways
but it like ignores if statements

Did you try putting the while true loop in different places?

just put all script in while true do and still no

Is this a serverscript or a local script??

Localscript because

put this here because it was not long enough

this is local script inside textlebel

You need to use a constant if statement (in a seperate thread) using a while loop:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Prices = Player:WaitForChild("Prices")
local Upgrades = Player:WaitForChild("Upgrades")
local WalkSpeedUpgradePrice = Prices.WalkSpeedUpgradePrice
local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade

local Abbreviations = {"", "K", "M", "B", "T", "Qa", "Qi",}

local function Format(value, decimals)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = Abbreviations [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ decimals) / (1000 ^ ex))) / (10 ^ decimals)

	return ("%."..decimals.."f%s"):format(normal, abbrevs)
end

local function UpdateText(newValue, max)
    if newValue == nil and max then
        script.Parent.Text = max
        return
    else          
	    local FormattedText = Format(newValue, 2)
	    script.Parent.Text = FormattedText
    end
end

spawn(function()
    while true do
        if WalkSpeedUpgrade.Value == 5 then
            UpdateText(WalkSpeedUpgradePrice.Value, nil)
        else
            UpdateText(nil, "MAX")
    end
    wait(.05)
end)

WalkSpeedUpgradePrice.Changed:Connect(UpdateText)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local Prices = Player:WaitForChild("Prices")
local Upgrades = Player:WaitForChild("Upgrades")
local WalkSpeedUpgradePrice = Prices.WalkSpeedUpgradePrice
local WalkSpeedUpgrade = Upgrades.WalkSpeedUpgrade

local Abbreviations = {"", "K", "M", "B", "T", "Qa", "Qi",}

local function Format(value, decimals)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = Abbreviations [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ decimals) / (1000 ^ ex))) / (10 ^ decimals)

	return ("%."..decimals.."f%s"):format(normal, abbrevs)
end

local function UpdateText(newValue)
if newValue >= 5 then
script.Parent.Text = "MAX"
else
	local FormattedText = Format(newValue, 2)

	script.Parent.Text = FormattedText
end
end

UpdateText(WalkSpeedUpgradePrice.Value)
WalkSpeedUpgradePrice.Changed:Connect(UpdateText)

Sorry im on mobile

1 Like

nah your script doesn’t work
aaaa

YES FINALLY THX SO MUCH (sorry for caps)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.