Problem tweening a boolean value

Hello
I would like to change a boolean value between true and false every 2 seconds.
It should be pretty straightforward but for some reason I cannot make it work:

ts = game.TweenService
local x = Instance.new("BoolValue", workspace)
x.Value = false

local info_beacon = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 0) 
local goal_beacon = {Value = true} 
local tweenBeacon = ts:Create(x, info_beacon, goal_beacon)

tweenBeacon:Play()

Any ideas?
Thanks in advance

You shouldn’t use tweens for that. You should just put it in a loop like so:

--//Initialization
local x = Instance.new("BoolValue")
x.Value = false
x.Parent = workspace

--//Loops
while x and task.wait(2) do
	x.Value = not x.Value
	
	task.wait(2)
	x.Value = not x.Value
end

(also don’t use the second parameter of Instance.new as it has performance issues, just set the parent last manually)

Should I use everywhere in my code task.wait(n), instead of wait(n)?

1 Like

Yes, as task.wait(n) is a better and more efficient version of wait(n). Here’s a post on it: