Making An ATM SurfaceGui

  1. 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
  1. 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
  1. 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 :smile:

The value isn’t updating because you’ve made the variable out of the loop.

Hello, how are you doing?

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)

yeah i already tried putting the variable inside of the loop, but still doesnt work

And if this is on a Script you cannot use:

game:GetService("Players").LocalPlayer

I’m assuming it’s a local script inside a Frame or a TextLabel. So he is allowed to use .LocalPlayer

thank you the script is working now :slight_smile:

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!

1 Like

@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

2 Likes

The only thing i did was get his code and modify it a little bit with the .Changed and .Value, but thanks for correcting me!

alright! will keep that in mind

1 Like

Thank you for sharing :smile: i’ll use this script as reference too