Tween doesn't stop when a value change is detected

I currently have a script that is meant to play a tween when a value is set to true, and stop the tween when the value is set to false. The tween gets played when the value gets set to true, but doesn’t stop when the value changes. Here’s my script:

-- Variables above

britvalue:GetPropertyChangedSignal("Value"):Connect(function()
	if britvalue.Value == true then
		if ameriflag.Decal.Transparency == 0 then
			local goal = {Position = bottomvalue}
			local ti = TweenInfo.new((bottomvalue.Y - ameriflag.Position.Y)/0.5)
			local tween = ts:Create(ameriflag, ti, goal)
			tween:Play()
			while true do
				wait(1)
				if script.Parent:WaitForChild("BritishIn").Value == true then
				else
					tween:Pause()
					break
				end
				if tween.Completed then
					for i, v in pairs(ameriflag:GetChildren()) do
						if v:IsA("Decal") then
							v.Transparency = 1
						end
					end
					break
				end
			end
		end
		for i, v in pairs(britflag:GetChildren()) do
			if v:IsA("Decal") then
				v.Transparency = 0
			end
		end
		local goal = {Position = topvalue}
		local ti = TweenInfo.new((topvalue.Y - britflag.Position.Y)/0.5)
		local tween = ts:Create(britflag, ti, goal)
		tween:Play()
		while true do
			wait(1)
			if script.Parent:WaitForChild("BritishIn").Value == true then
			else
				tween:Pause()
				break
			end
			if tween.Completed then
				game.ReplicatedStorage.FlagA.Value = true
				break
			end
		end
	end
end)
3 Likes

If britvalue is a BoolValue, use a .Changed event instead, this event also gives you the new value of the BoolValue.

1 Like

I’m using a while true do loop and validating the value of the boolvalue each time the loop runs, but for some reason it’s not detecting the change.

1 Like

Still need help with this if anyone can offer assistance.

1 Like

Still need an answer, if anyone can give one.

Try doing Tween:Cancel() to fix this

1 Like