What do you want to achieve? Keep it simple and clear!
Making a script to let an ATM to display how much money a player can withdraw
What is the issue? Include screenshots / videos if possible!
The screen did display “$0” when I first joined, but it doesn’t change when the value increase
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
yes. I tried putting the “screenMoney” inside of the loop, using “ATMMoney” directly inside of the loop
local player = game:GetService("Players").LocalPlayer
local ATMMoney = player:WaitForChild("ATM").Value
local screenMoneyK = ATMMoney/1000
local screenMoneyM = ATMMoney/1000000
local atm = game.Workspace.atm
while wait() do
for i, v in pairs(atm:GetDescendants()) do
if v.Name == "TextLabel" then
if ATMMoney >= 10000 and ATMMoney < 1000000 then
v.Text = "$"..screenMoneyK.."K"
else if ATMMoney >= 1000000 then
v.Text = "$"..screenMoneyM.."M"
else
v.Text = "$"..ATMMoney
end
end
end
end
end
im still new to scripting, please give me some hints and advice
Remove the .Value infront of the ATMMoney variable, and everytime you’re gonna use it put .Value infront of it.
Change the while loop with a .Changed function, so it only detects everytime the value of the ATMMoney changed.
local player = game:GetService("Players").LocalPlayer
local ATMMoney = player:WaitForChild("ATM")
local screenMoneyK = ATMMoney/1000
local screenMoneyM = ATMMoney/1000000
local atm = game.Workspace.atm
ATMMoney.Changed:Connect(function()
for i, v in pairs(atm:GetDescendants()) do
if v.Name == "TextLabel" then
if ATMMoney.Value >= 10000 and ATMMoney.Value < 1000000 then
v.Text = "$"..screenMoneyK.."K"
else if ATMMoney.Value >= 1000000 then
v.Text = "$"..screenMoneyM.."M"
else
v.Text = "$"..ATMMoney.Value
end
end
end
end
end)
No problem, hope you figured out the issue!
Though, this could’ve easily fixed if you checked the wiki. Try reading the articles some day, they help a lot!
@TrashMakeRice your solution won’t work for values over 1000
local player = game:GetService("Players").LocalPlayer
local ATMMoney = player:WaitForChild("ATM")
local K = 1000
local M = 1000000
local atm = workspace.atm
local AllTextLabels = {}
for _, descendant: Instance in pairs(atm:GetDescendants()) do
if descendant:IsA("TextLabel") then
local TextLabel: TextLabel = descendant
if TextLabel.Name == "TextLabel" then
table.insert(AllTextLabels, TextLabel)
end
end
end
ATMMoney.Changed:Connect(function(currrentMoney)
for _, TextLabel: TextLabel in ipairs(AllTextLabels) do
if ATMMoney >= currrentMoney and ATMMoney < currrentMoney then
TextLabel.Text = "$" .. currrentMoney / K .. "K"
else
if ATMMoney >= 1000000 then
TextLabel.Text = "$" .. currrentMoney / M .. "M"
else
TextLabel.Text = "$" .. currrentMoney
end
end
end
end)
This will error because you are trying to divide an instance with 1000