WooleyWool
(AWildWooleyWool)
December 22, 2020, 3:43am
#1
Hi, I am trying to have the text change if the value changed that is parented to the player, but it’s not working. Here is my code:
player:FindFirstChild("PrimaryColor"):GetPropertyChangedSignal("Value"):Connect(function()
script.Parent.Text = "Primary Color: " .. player:FindFirstChild("PrimaryColor").Value
end)
1 Like
lifacy
(lifacy)
December 22, 2020, 3:44am
#2
Try using WaitForChild instead. Also, you are sure you are putting a value object in, correct? Any errors at all in the output?
2 Likes
WooleyWool
(AWildWooleyWool)
December 22, 2020, 3:47am
#3
That didn’t change anything, I did have it set to a value but that’s not changing anything. No errors either.
lifacy
(lifacy)
December 22, 2020, 3:48am
#4
Does the value ever change? I usually set the text two times, right when the object is added and after it has changed.
WooleyWool
(AWildWooleyWool)
December 22, 2020, 3:49am
#5
It gets set when you join the game, and if you et a different color, it’ll change to that value.
First of all, I’m not sure why you’re using FindFirstChild to get it everytime when you can just use player.PrimaryColor.
Second of all, it’s better to use Changed for ValueObjects instead of GetPropertyChangedSignal.
The code looks like it should work. Maybe the problem is somewhere else in the script? Can you show more of the script?
Feugazi
(Feugazi)
December 22, 2020, 4:16am
#7
Are you having any errors in the output?
WooleyWool
(AWildWooleyWool)
December 22, 2020, 4:42am
#8
That’s all that’s in the script except the player variable, which is getting the local player. this script is a local script too.
WooleyWool
(AWildWooleyWool)
December 22, 2020, 4:58am
#9
Hmm oddly it works when I choose another color from the menu, but not when it starts up… odd…
lexidogfur
(lexidog)
December 22, 2020, 6:14am
#10
Then your issue is that you’re not applying the initial value. The script is running after it gets changed, so the initial event doesn’t fire. (i hope that made sense sorry)
function UpdatePrimaryColorDisplay(color)
script.Parent.Text = "Primary Color: " .. color
end
UpdatePrimaryColorDisplay(player.PrimaryColor.Value)
player.PrimaryColor.Changed:Connect(UpdatePrimaryColorDisplay)
The changed event on ValueObjects returns the new value, so we don’t need to grab it manually. GetPropertyChangedSignal does not for performance reasons.
1 Like