Hello,
I am making a system when you select an object it selects it with an outline, but for some reason, it doesn't change the "on" value to true therefore it won't turn off.
mouse.Button1Down:Connect(function() local on = false if on == false then local outline = Instance.new('SelectionBox') outline.Parent = mouse.Target outline.Adornee = mouse.Target outline.Name = "Outline" on = true elseif on == true then mouse.Target.Outline:Destroy() on = false end end)
Thank You.
mouse.Button1Down:Connect(function() local on = false if on == false then local outline = Instance.new('SelectionBox') outline.Parent = mouse.Target outline.Adornee = mouse.Target outline.Name = "Outline" on = true elseif on == true then -- It will never be true because its been set to false at the beginning. mouse.Target.Outline:Destroy() on = false end end)
CORRECT VERSION:
mouse.Button1Down:Connect(function() if on == false then local outline = Instance.new('SelectionBox') outline.Parent = mouse.Target outline.Adornee = mouse.Target outline.Name = "Outline on = true elseif on == true then mouse.Target.Outline:Destroy() on = false end end)
Seems to be throwing an error,
W003: Global 'on' is only used in the enclosing function; consider changing it to local. it happened to me before when testing.