Need Help With a Script

I have coded a script to put the Values of to NumberValues onto guis, but the second function wont fire, but the first dose

Player.PlayerGui.ScreenGui.leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(game.ReplicatedStorage.userData[Player.Name].Credits.Value)
game.ReplicatedStorage.userData[Player.Name].Credits.Value:GetPropertyChangedSignal("Value"):Connect(function()
	Player.PlayerGui.ScreenGui.leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(game.ReplicatedStorage.userData[Player.Name].Credits.Value)

end)
	-- Wont Fire

Player.PlayerGui.ScreenGui.leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(game.ReplicatedStorage.userData[Player.Name].StudsDriven.Value)
game.ReplicatedStorage.userData[Player.Name].StudsDriven.Value:GetPropertyChangedSignal("Value"):Connect(function()
	Player.PlayerGui.ScreenGui.leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(game.ReplicatedStorage.userData[Player.Name].StudsDriven.Value)
end)

Are you getting any errors when server startup?

No, I don’t get any errors on startup

Are you sure that the value is present on replicated storage could you try to put a print inside the GetPropertyChangedSignal function?

It doesn’t print anything, There both the same kind of value, the only thing that is different is the Name of the value

Could you send the Comma function, it may be yielding it forever?

Well it looks a bit strange if there are not errors and the first function fire, there are no reason of why the second function wont fire…

Here:

function Comma(v10)
	while true do 
		v10, k = string.gsub(v10,"^(-?%d+)(%d%d%d)", '%1,%2')
		if (k == 0)	then
			break
		end
	end
	return v10

end

Oh! I see the problem, it doesn’t seem to break the loop I have another comma function if you would like to try it.

function comma(amount)
	if (math.abs(amount) < 1000) then 
		return tostring(amount) 
	end

	local str = (amount < 0 and "-" or "") .. tostring(math.abs(math.floor(amount))):reverse():gsub("%d%d%d","%1,"):gsub(",$",""):reverse()

	if (not (amount == math.floor(amount))) then
		str = str .. "." .. (tostring(amount):match("%d+.$"))
	end

	return str
end

You obviously don’t have to use it but try and replace it to see if it works

Sadly, i dosent work

function comma(amount)
	if (math.abs(amount) < 1000) then 
		return tostring(amount) 
	end

	local str = (amount < 0 and "-" or "") .. tostring(math.abs(math.floor(amount))):reverse():gsub("%d%d%d","%1,"):gsub(",$",""):reverse()

	if (not (amount == math.floor(amount))) then
		str = str .. "." .. (tostring(amount):match("%d+.$")) -- here its underlined as a error
	end

	return str
end

Did you try and run it? Because it should work. Nothing else should yield the function.

Its underlined red because of something wrong with the script editor

This is a picture of the script:

I don’t see a problem with the script, try making variables, for example PlayerGui and try to use :WaitForChild where possible

I made a quick version you could try to use

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local leaderstatAmounts = ScreenGui:WaitForChild("leaderstatAmounts")

leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(game.ReplicatedStorage.userData[Player.Name].Credits.Value)
ReplicatedStorage.userData[Player.Name].Credits.Value:GetPropertyChangedSignal("Value"):Connect(function()
	leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(ReplicatedStorage.userData[Player.Name].Credits.Value)

end)

leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(ReplicatedStorage.userData[Player.Name].StudsDriven.Value)
ReplicatedStorage.userData[Player.Name].StudsDriven.Value:GetPropertyChangedSignal("Value"):Connect(function()
	leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(ReplicatedStorage.userData[Player.Name].StudsDriven.Value)
end)

With the new script, it still puts the text on the first label, but for some reason it doesn’t do it for the second.

And you’re not getting any errors?

Yes i get this error: PlayerGui.ScreenGui.Client:155: attempt to index number with ‘GetPropertyChangedSignal’

Oh! I see the problem. I made a fixed version for you!

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PlayerGui = Player:WaitForChild("PlayerGui")
local ScreenGui = PlayerGui:WaitForChild("ScreenGui")
local leaderstatAmounts = ScreenGui:WaitForChild("leaderstatAmounts")

local userDataFolder = ReplicatedStorage:WaitForChild("userData")
local userData = userDataFolder:FindFirstChild(Player.Name)

leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(userData.Credits.Value)
userData.Credits:GetPropertyChangedSignal("Value"):Connect(function()
	leaderstatAmounts.Credits.TextLabel.Text = "$"..Comma(userData.Credits.Value)

end)

leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(userData.StudsDriven.Value)
userData.StudsDriven:GetPropertyChangedSignal("Value"):Connect(function()
	leaderstatAmounts.Miles.TextLabel.Text = ""..Comma(userData.StudsDriven.Value)
end)

The problem was that you did Credits.Value:GetPropertyChangedSignal, and that doesn’t work you have to remove the .Value because the value is returning a number.

It worked! Thank you for your help!