.Changed not working for some reason

Not sure why but it doesn’t work as in the interface does not show the correct number of coins/gems.

image
image
image
image

Value is supposed to change on client-side gui as of the second picture. The actual values of the coins are functioning in which the IntValues reflect the correct data. 685 in this case, but despite being loaded in, the gui text does not change.

2 Likes

It might be because in your Coins.Changed:Connect(function() you forgot to put .value after Coins
(same with gems)

2 Likes

You cant check changed for numbers. Returns an error when I put …Value.Changed

2 Likes

Use GetPropertyChangedSignal its much easier and better

3 Likes
Player.CharacterAdded:Connect(function()
	Player:FindFirstChild("Values").Coins:GetPropertyChangedSignal("Value"):Connect(function()
		CoinsDisplay.Text = tostring(Player.Values.Coins.Value)

	end)

	Player:FindFirstChild("Values").Gems:GetPropertyChangedSignal("Value"):Connect(function()
		GemsDisplay.Text = tostring(Player.Values.Gems.Value)
	end)
end)

I’ve tried with PropertyChanged and Values changed, the gui text still returns 0.

2 Likes

Why not just use a LocalScript unless you seriously need it to run on the server (take the advice from SelDraken‘s post)

I meant to say that you should change the UI on the client

2 Likes

If you are making the change on the server, you need to use a remote event to tell the client it has changed.

3 Likes

Also, just to clear things up, if you are using a numbervalue instance, then you would NOT use GetPropertyChangedSignal

And Player.CharacterAdded:Connect, will work on the client.

3 Likes

I’m not making a change on the server. The script is a datastore script in which it loads the values for coins and gems in the folder “Values”. The local script which is the one shown in the original post is checking if there are any changes to it, which then would display the values on the player’s screen (as seen on the 2nd picture), there is no changes made with the local script in regards to the values.

The problem is that .Changed and now PropertySignal doesn’t work, as it doesn’t track the values being changed on the ServerSide. What’s weird about this is that it previously worked as intended.

2 Likes

The local script is under the ScreenGUI which is the first picture. I apologise for not mentioning what class it is.

3 Likes

If you are reading the values from a datastore script, then that datastore script must be a server script.

Can you show where that datastore scrips is writing the values to the numbervalue instances?

2 Likes

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")

local database = DataStoreService:GetDataStore("data")
local sessiondata = {}

local function setup(player)
	local values = Instance.new("Folder")
	values.Parent = player
	values.Name = "Values"

	local coins = Instance.new("NumberValue")
	coins.Name = "Coins"
	coins.Parent = values

	local gems = Instance.new("NumberValue")
	gems.Name = "Gems"
	gems.Parent = values

	local traylimit = Instance.new("NumberValue")
	traylimit.Name = "TrayLimit"
	traylimit.Parent = values

-- assume pcall, with data loaded as print statement returns correct values

        sessiondata[player.UserId] = pdata

	gems.Value = sessiondata[player.UserId].Gems
	gems.Changed:Connect(function()
		sessiondata[player.UserId].Gems = gems.Value
	end)

	coins.Value = sessiondata[player.UserId].Coins
	coins.Changed:Connect(function()
		sessiondata[player.UserId].Coins = coins.Value
	end)

	traylimit.Value = sessiondata[player.UserId].TrayLimit
	traylimit.Changed:Connect(function()
		sessiondata[player.UserId].TrayLimit = traylimit.Value
	end)


end

Hope this is sufficient for you, let me know if you need more context.

2 Likes

I still think the issue is that the client is not getting the change you are making from the server.

Have you tried to, instead of Changed:Connect, instead
just put a task.wait(10) and then do print(coins.Value) to see if the client is even getting
the value or not.

2 Likes

Same issue. Characteradded doesn’t work as well. Let me check the Coins for you.

image

2 Likes

Same issue as in when you printed the value, it was 0, or when you printed it, it was 685.

And I mean to do this on a local script, maybe put it under StarterCharacrerScripts

That way we make sure the client is actually able to ‘see’ the values.

2 Likes

I think your first part was correct.
I checked using the task.wait() idea you suggested, and it turns out that it returns 685 for both before the wait and after. I’m not sure if this is a characteristic of DataStore, but this explains why .Changed doesn’t work.

2 Likes

try this

Player:WaitForChild("Values").Coins.Changed:Connect(function(value)
       CoinsDisplay.Text = tostring(value)
end)

by the way we need to see the script where you changed the “Coins” value, we need more info

1 Like

If the client is seeing the correct value, but Changed is not firing, then the datastore is changing the value, before the local script has time to set up the .Changed handlers

Probably if you put a task.wait(10) in the datastore script, to give the client time to set up the .Changed handler, I bet you would see it fire the change.

Maybe to solve this, is to read the values from the coins.Value, and others just after you set up the .Changed handlers, and set your gui to a starting value of this.

1 Like

Your solution worked the first time in which it properly displayed 685, then the same issue arose again. The script is

1 Like

Could you explain what you mean by:

I’ve tried to set the text initially as the starting value of the player’s data coins like you’ve said, but for some reason it doesn’t work either and its stuck on 0.

wait(5)
	CoinsDisplay.Text = Player.Values.Coins.Value
	GemsDisplay.Text = Player.Values.Gems.Value
Player.CharacterAdded:Connect(function()
	CoinsDisplay.Text = Player.Values.Coins.Value
	GemsDisplay.Text = Player.Values.Gems.Value
end)
1 Like