Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Part Selection Value Not Changing?

Asked by 4 years ago

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.

2 answers

Log in to vote
0
Answered by
6zk8 95
4 years ago
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)
Ad
Log in to vote
0
Answered by 4 years ago

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.

Answer this question