How to detect when 2 StringValues change

I have this script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local YesOrNo1 = ReplicatedStorage.YesOrNo1
local YesOrNo2 = ReplicatedStorage.YesOrNo2
local DB = false
local AnswerBoard1 = game.Workspace.TextBoard1
local AnswerText1 = AnswerBoard1.SurfaceGui.Answer
local AnswerBoard2 = game.Workspace.TextBoard2
local AnswerText2 = AnswerBoard2.SurfaceGui.Answer

YesOrNo1.Changed:Connect(function()
	AnswerText1.Text = YesOrNo1.Value
	
end)

YesOrNo2.Changed:Connect(function()
	AnswerText2.Text = YesOrNo2.Value
	
end)

And I want to know how to detect when both “YesOrNo1” and “YesOrNo2” both change, like at the moment they are inactive, then the player presses a button which changes one of them, then a separate button that changes the other one. How do I detect when they have both changed?

1 Like

Is there an error in the console?

No, everything is fine, I just have no idea how to know when both of them have changed. Is there a way to know when both functions have gone off, that is what I need.

Then why not just use variables that are set to true if both of them changed?

local YesOrNo1HasChanged = false
local YesOrNo2HasChanged = false

YesOrNo1.Changed:Connect(function()
	AnswerText1.Text = YesOrNo1.Value
	YesOrNo1HasChanged = true
end)

YesOrNo2.Changed:Connect(function()
	AnswerText2.Text = YesOrNo2.Value
	YesOrNo2HasChanged = true
end)
YesOrNo1.Changed:Connect(function()
    print("YesOrNo1 changed to:", YesOrNo1.Value)
    AnswerText1.Text = YesOrNo1.Value
end)

YesOrNo2.Changed:Connect(function()
    print("YesOrNo2 changed to:", YesOrNo2.Value)
    AnswerText2.Text = YesOrNo2.Value
end)

Remember to modify the values from the server and not from the client.

I fixed it, but thanks for the help anyway.

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