Value.changed not working

Im trying to check if the value is changing, it doesn’t work unless I click another button, then it works.

local function updateTexture(newPetID)
	petID = newPetID
	repeat 		front.Texture = "rbxthumb://type=Asset&id="..petID.."&w=150&h=150" wait(.1) until 		front.Texture == "rbxthumb://type=Asset&id="..petID.."&w=150&h=150"
	repeat 	back.Texture = "rbxthumb://type=Asset&id="..petID.."&w=150&h=150" wait(.1) until 	back.Texture == "rbxthumb://type=Asset&id="..petID.."&w=150&h=150"
end

plr.Data.PetID.Value.Changed:Connect(updateTexture)
local l = game.ReplicatedStorage:WaitForChild("Pet"):WaitForChild("Eggdog"):WaitForChild("Normal")

l.OnServerEvent:Connect(function(plr)
	local thing = plr:WaitForChild("Data"):WaitForChild("PetID")
	thing.Value = "12796463132" -- Primary ID
	thing.Value = "12995552929" -- Decoy id
	thing.Value = "12796463132" -- Primary ID
end)

I tried making a decoy ID but that doesn’t even work either

-- Remove Value from PetID.Value, we are getting the value when the PetID is changed.
plr.Data.PetID.Changed:Connect(updateTexture)

If you just want to get the Value being changed, do

plr.Data.PetID:GetPropertyChangedSignal("Value"):Connect(updateTexture)

I did both of these before but i still have the same problem

Can you show a video by any chance? What do you mean when you say it doesn’t work until you lick another button?

Why are you repeating texture assignment, I do not believe you need a loop for this.

When you set the value three times in a row like this, only one changed event will fire. There is not enough time between assignments for multiple .Changed to fire. Are you expecting to see the Decoy id?

1 Like

No I want to see the Primary ID, since the .changed isn’t working, i thought changing the id to something then turning it back would work.

image
There are two of these “Select” buttons,
When i click the first one it doesn’t appear sometimes, it 100% appears when i click the other one, I dont want that i want it to 100% work when i click it the first time

!!! THERE IS NO OUTPUT ERRORS, THAT IS ANOTHER SCRIPT THAT IM WORKING ON !!!

When you run the game, does it default to the ID of the first one? If so, that’s probably why it’s not working.

The docs say you want to use plr.Data.PetID.Changed:Connect can you make sure you are using a StringValue?

-- A StringValue stores one string
local vString = Instance.new("StringValue")
vString.Changed:Connect(print)

-- This fires Changed with "Hello" (not "Value")
vString.Value = "Hello"

What do you mean floofy? Also gert,


Im using a datastore for this and yes, this is a stringvalue

That’s probably why it’s not working. When you start the game, it defaults to a value, and clicking the button “changes it” to that exact value, thus not firing .Changed or :GetPropertyChangedSignal. That sounds plausible considering the behavior you’re describing.

Ohhh! So you mean when i put it at one of those values, when i leave it saves to that value, and when i join back the value there is the same as that one, Though
image
wont this fix the problem?

I don’t really know what you’re trying to do by setting the value back and forth. That’s not gonna fire Changed, I don’t think it will fix anything.

1 Like

when you set and set it back like that the client doesn’t see the in-between. It happens in the same “frame” so the server only sends the final value, which probably does not fire a Changed event if it’s the same.

1 Like

image
I found a better solution for gert’s description, I removed a value and added a wait

1 Like

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