How Do I Show this UI upon a value changing?

So, I have this script that is supposed to show a gui when a value changes. But when I change the value, the gui doesn’t appear. I have tried using .Changed and that worked, well mostly. It kinda just only showed the gui when the value changes to a different one from the previous. How do I fix this?


script.Parent.Parent.CurrentUnit:GetAttributeChangedSignal("Value"):Connect(function()
	local value = script.Parent.Parent.CurrentUnit:GetAttribute("Value")
	script.Parent.Parent.Tower.Text = value
	script.Parent.Parent.Tier.Text = checkTier(value)
	script.Parent.Parent.Size = UDim2.new(0.01, 0, 0.01, 0)
	script.Parent.Parent.Visible = true
	script.Parent.Parent:TweenSize(UDim2.new(0.256, 0, 0.581, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Back, 0.5, true)
	for i,tower in ipairs(workspace.ViewportFrames.SummonedUI:GetChildren()) do
		--print(script.Parent.Parent.CurrentUnit.Value, tower.Name)
		if script.Parent.Parent.CurrentUnit.Value == tower.Name or script.Parent.Parent.CurrentUnit.Value == tower.Config.OriginalTower.Value then
			local clone = tower:Clone()
			clone.Parent = script.Parent.WorldModel
		end
	end
	for i = 1,100 do
		wait(3 / 100)
	end
	if script.Parent.Parent.Visible then
		script.Parent.Parent:TweenSize(UDim2.new(0.01, 0, 0.01, 0), Enum.EasingDirection.In, Enum.EasingStyle.Back, 0.5, false)
		wait(0.5)
		script.Parent.Parent.Visible = false
	end
end)

Sorry, what are you trying to explain? You’ve said that you need the UI to show when a value changes, but then you say “the GUI only showed when the value changes”. I don’t get what the problem is.

1 Like

sorry, I may have written it extremely wrong, I was in a rush while making this post. When I used .Changed, it only executed the script upon changing the value, not if the value changes to the previous value, or if the value is the same twice.

1 Like