Updating TextLabel with GetPropertyChangedSignal

I’m practicing scripting and created a scenario where you have to collect 4 items to open a door. I would like to get the textLabel to update to show how many items have been collected (“1/4 Collected”, “2/4 Collected”, etc.). I have a value stored in replicated storage and it increases when items are collected. I am using GetPropertySignalChanged in the TextLabel script but it is not updating when the value changes. Anyone have insight into why this isnt working?

local text = script.Parent
local eCollected = game.ReplicatedStorage.eCollected

text.Text = eCollected.Value.."/4 Collected!"

eCollected:GetPropertyChangedSignal("Value"):Connect(function()
	text.Text = eCollected.Value.."/4 Collected!"
end)

Are you using a local script when checking for updates? Because I tested this script and it seems to work fine for me
(Nevermind it works fine with a local script too, is your int value actually updating?)

2 Likes

Yes. I have it set to print Value when items are collected. The printed value increases but the textlabel doesnt update. It stays 0/4.

Hmm… Now I’m kind of confused, could it be something with how you’re collecting the items? Like if it’s being done on a local script?

Video:

1 Like

I am collecting them through touched events in a server script. Here is the code for collecting the items and opening the door.

local button = game.Workspace.button.ClickDetector
local door = game.Workspace.door
local e1 = game.Workspace.Evidence.e1
local e2 = game.Workspace.Evidence.e2
local e3 = game.workspace.Evidence.e3
local e4 = game.Workspace.Evidence.e4
local Evidence = game.Workspace.Evidence
local eCollected = game.ReplicatedStorage.eCollected.Value
local openSound = game.Workspace.door_open
local buzzer = game.Workspace["Britain's Got Talent - Buzzer"]
local collected = game.Workspace["Coin Collect 2 - SFX"]


--Evidence Collection (increase eCollected value and destroy part)

for i, child in pairs(Evidence:GetChildren()) do
	if child:IsA("BasePart") then
		child.Touched:Connect(function()
			eCollected = eCollected + 1
			child:Destroy()
			print(eCollected.."/4 Collected")
			collected:Play()
		end)
	end
end

--Door function (eCollected must = 4)
local function openDoor()
	if eCollected >= 4 and door.Transparency == 0 then
		door.Transparency = 1
		door.CanCollide = false
		openSound:Play()
	elseif eCollected ~=4 and door.Transparency ~=1 then
		buzzer:Play()
	end
end

button.MouseClick:Connect(openDoor)

when you make variables that reference numbers they create copies of the numbers

if you reference a table/object then it refers to the same object

In your case you referenced the eCollected.Value (which is a number) so the eCollected variable in the server script is not editing the actual value

you have to change eCollected to the value instance and then change with eCollected.Value = something

1 Like

Changing this in server script got it working! Tysm!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.