GetPropertyChangedSignal does not work

Server:

local ServerStorage = game:GetService("ServerStorage")
local statUnder = ServerStorage:WaitForChild("statUnder")

local abbreviations = {
	"",
	"K",
	"M",
	"B",
	"T"
}

local function abbreviateNumbers(Number)
	for  i = 1, #abbreviations do
		if Number < 10 ^ (i * 3) then
			if abbreviations[i] == "∞" then
				return "∞"
			else
				return math.floor(Number / ((10 ^ ((i - 1) * 3)) / 100)) / (100) .. abbreviations[i]
			end
		elseif tostring(Number) == "Inf" then
			return "∞"
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		local Head = character:WaitForChild("Head")
		local ld = player:WaitForChild("leaderstats")

		repeat task.wait(0.35) until character:FindFirstChild("Head")
		Head = character.Head

		local uiClone = statUnder:Clone()
		uiClone.Name = "StatUnderClone"
		uiClone.Parent = Head
		
		local uiClone2 = ServerStorage:WaitForChild("rebirthUnder")
		uiClone2.Name = "RebirthUnderClone"
		uiClone2.Parent = Head
		
		local function update()
			uiClone.stat.Text = abbreviateNumbers(player.leaderstats.Power.Value + ld.Mass.Value).. " Power"
			print("update Power")
		end
		
		local function updateRebirth()
			if player.leaderstats.Rebirth.Value == 0 then
				uiClone2.stat2.Text = "🤓Noob"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 1 then
				uiClone2.stat2.Text = "😑Beginner"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 2 then
				uiClone2.stat2.Text = "🙂Rookie"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 3 then
				uiClone2.stat2.Text = "🔰Novice"
			elseif player.leaderstats.Rebirth.Value == 4 then
				uiClone2.stat2.Text = "🧑‍🎓 Learner"
			elseif player.leaderstats.Rebirth.Value == 5 then
				uiClone2.stat2.Text = "🎓Trainee"
			elseif player.leaderstats.Rebirth.Value == 6 then
				uiClone2.stat2.Text = "👩🏻‍💻Apprentice"
			elseif player.leaderstats.Rebirth.Value == 7 then
				uiClone2.stat2.Text = "🥊Amateur"
			elseif player.leaderstats.Rebirth.Value == 8 then
				uiClone2.stat2.Text = "🚆Intermediate"
			end
		end

		update()
		
		wait(1)
		
		updateRebirth()

		player.leaderstats.Power:GetPropertyChangedSignal("Value"):Connect(update)
		player.leaderstats.Mass:GetPropertyChangedSignal("Value"):Connect(update)
		player.leaderstats.Rebirth:GetPropertyChangedSignal("Value"):Connect(updateRebirth)
		
		character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		
	end)
end)

So this is my script for showing the player’s strength over the player’s head, but when the strength is increased, the strength over the head is not updated, and print is not displayed. Why? Т

6 Likes

GetPropertyChangedSignal is not very good for Value instances. They have their own dedicated function which is:

StringValue.Changed:Connect(function()

This function fires whenever the value is changed

1 Like

like this?:

player.leaderstats.Power.Value.Changed:Connect(update)
player.leaderstats.Mass.Value.Changed:Connect(update)
player.leaderstats.Rebirth.Value.Changed:Connect(update)
3 Likes

No you have to remvoe the .Value, since it’s a function dedicated to Values it will only work on the value property

2 Likes

Can you give me an exact example of the code? If it’s not too much trouble

2 Likes
player.leaderstats.Power.Changed:Connect(update)
player.leaderstats.Mass.Changed:Connect(update)
player.leaderstats.Rebirth.Changed:Connect(update)
2 Likes

Is it supposed to work? Thank you for your reply

2 Likes

Yeah let me know if it does, it should

1 Like

so here’s my final script:

local ServerStorage = game:GetService("ServerStorage")
local statUnder = ServerStorage:WaitForChild("statUnder")

local abbreviations = {
	"",
	"K",
	"M",
	"B",
	"T"
}

local function abbreviateNumbers(Number)
	for  i = 1, #abbreviations do
		if Number < 10 ^ (i * 3) then
			if abbreviations[i] == "∞" then
				return "∞"
			else
				return math.floor(Number / ((10 ^ ((i - 1) * 3)) / 100)) / (100) .. abbreviations[i]
			end
		elseif tostring(Number) == "Inf" then
			return "∞"
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		local Head = character:WaitForChild("Head")
		local ld = player:WaitForChild("leaderstats")

		repeat task.wait(0.35) until character:FindFirstChild("Head")
		Head = character.Head

		local uiClone = statUnder:Clone()
		uiClone.Name = "StatUnderClone"
		uiClone.Parent = Head
		
		local uiClone2 = ServerStorage:WaitForChild("rebirthUnder")
		uiClone2.Name = "RebirthUnderClone"
		uiClone2.Parent = Head
		
		local function update()
			uiClone.stat.Text = abbreviateNumbers(player.leaderstats.Power.Value + ld.Mass.Value).. " Power"
			print("update Power")
		end
		
		local function updateRebirth()
			if player.leaderstats.Rebirth.Value == 0 then
				uiClone2.stat2.Text = "🤓Noob"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 1 then
				uiClone2.stat2.Text = "😑Beginner"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 2 then
				uiClone2.stat2.Text = "🙂Rookie"
				print(uiClone2.stat2.Text)
			elseif player.leaderstats.Rebirth.Value == 3 then
				uiClone2.stat2.Text = "🔰Novice"
			elseif player.leaderstats.Rebirth.Value == 4 then
				uiClone2.stat2.Text = "🧑‍🎓 Learner"
			elseif player.leaderstats.Rebirth.Value == 5 then
				uiClone2.stat2.Text = "🎓Trainee"
			elseif player.leaderstats.Rebirth.Value == 6 then
				uiClone2.stat2.Text = "👩🏻‍💻Apprentice"
			elseif player.leaderstats.Rebirth.Value == 7 then
				uiClone2.stat2.Text = "🥊Amateur"
			elseif player.leaderstats.Rebirth.Value == 8 then
				uiClone2.stat2.Text = "🚆Intermediate"
			end
		end

		update()
		
		wait(1)
		
		updateRebirth()

		--player.leaderstats.Power:GetPropertyChangedSignal("Value"):Connect(update)
		--player.leaderstats.Mass:GetPropertyChangedSignal("Value"):Connect(update)
		--player.leaderstats.Rebirth:GetPropertyChangedSignal("Value"):Connect(updateRebirth)
		
		player.leaderstats.Power.Changed:Connect(update)
		player.leaderstats.Mass.Changed:Connect(update)
		player.leaderstats.Rebirth.Changed:Connect(update)

		character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		
	end)
end)

and yet it doesn’t work.

1 Like

Here is what I would do, since these are values, instead of using :GetPropertyChangedSignal Just use .Changed, The value’s changed property only fires when the value of the value changes, so you don’t have to worry about the event firing when the value does not change, just write this instead.

player.leaderstats.Power.Changed:Connect(update) -- Just a reminder when using changed it returns the value.

1 Like

I’m a little confused, so what do I have to do to make it work properly?

1 Like

I believe the code is not wrong in the value changing part, try checking the functions.

1 Like

so it’s like the function itself doesn’t work. And by the way, here’s something else, maybe the problem is that this is a server script?

1 Like

Hey! Try this:

local ServerStorage = game:GetService("ServerStorage")
local statUnder = ServerStorage:WaitForChild("statUnder")

local abbreviations = {
	"",
	"K",
	"M",
	"B",
	"T"
}

local function abbreviateNumbers(Number)
	for  i = 1, #abbreviations do
		if Number < 10 ^ (i * 3) then
			if abbreviations[i] == "∞" then
				return "∞"
			else
				return math.floor(Number / ((10 ^ ((i - 1) * 3)) / 100)) / (100) .. abbreviations[i]
			end
		elseif tostring(Number) == "Inf" then
			return "∞"
		end
	end
end

local RebirthValues = {
	[0] = "🤓Noob",
	[1] = "😑Beginner",
	[2] = "🙂Rookie",
	-- ... complete the list
}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local leaderstats = player:WaitForChild("leaderstats")
		local Power = leaderstats:WaitForChild("Power")
		local Mass = leaderstats:WaitForChild("Mass")
		local Rebirth = leaderstats:WaitForChild("Rebirth")

		local Head = character:WaitForChild("Head")

		repeat task.wait(0.35) until character:FindFirstChild("Head")
		Head = character.Head

		local uiClone = statUnder:Clone()
		uiClone.Name = "StatUnderClone"
		uiClone.Parent = Head

		local uiClone2 = ServerStorage:WaitForChild("rebirthUnder")
		uiClone2.Name = "RebirthUnderClone"
		uiClone2.Parent = Head

		local function update()
			uiClone.stat.Text = abbreviateNumbers(Power.Value + Mass.Value).. " Power"
			print("update Power")
		end

		local function updateRebirth()
			uiClone2.stat2.Text = RebirthValues[Rebirth.Value]
		end

		update()

		task.wait(1)

		updateRebirth()
		
	

		Power.Changed:Connect(update())
		Mass.Changed:Connect(update())
		Rebirth.Changed:Connect(updateRebirth())

		character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

	end)
end)
1 Like

oh yea remove the () from update and updaterebirth in changed so it should be : Power.Changed:Connect(update) for all

1 Like

I did as you said, but when you dial the force, it still doesn’t change)

1 Like

Any errors in your output? Try to put this right after the uiClone2.Parent = head:

if uiClone2 then
			print("Exist") 
		else
			print("Doesn't Exist")	
		end
1 Like

1 Like

I tested this code and it works:

local abbreviations = {
	"",
	"K",
	"M",
	"B",
	"T"
}

local function abbreviateNumbers(Number)
	for  i = 1, #abbreviations do
		if Number < 10 ^ (i * 3) then
			if abbreviations[i] == "∞" then
				return "∞"
			else
				return math.floor(Number / ((10 ^ ((i - 1) * 3)) / 100)) / (100) .. abbreviations[i]
			end
		elseif tostring(Number) == "Inf" then
			return "∞"
		end
	end
end

local RebirthValues = {
	[0] = "🤓Noob",
	[1] = "😑Beginner",
	[2] = "🙂Rookie",
	-- ... complete the list
}

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local Power = script.Power
		local Mass = script.Mass
		local Rebirth = script.Rebirth
	

		local function update()
			print(abbreviateNumbers(Power.Value + Mass.Value).. " Power")
		end

		local function updateRebirth()
			print(RebirthValues[Rebirth.Value])
		end

		update()

		updateRebirth()

		Power.Changed:Connect(update)
		Mass.Changed:Connect(update)
		Rebirth.Changed:Connect(updateRebirth)

		character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

	end)
end)

so the issue seems to be getting the UIs from serverstorage. Maybe change the location to lighting?

1 Like

Also, the script is in ServerScriptService right?

1 Like