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
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
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”.
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)