Yup
character_limit_charlimit3423324
This was way too much work, damn (but I saw it as competition to myself at the end).
I COMPLETELY rewrote the script and it barely looks like it looked before. Your main issue was the way you put MouseButtion1 into the while loop and the touch variable also bugged the whole thing.
For now I made the script so you can hover over everything except the Baseplate and if you click on a part it locks the selectionbox. To unlock it you have to be on the locked part! If you want it to be so the locked part gets unlocked when clicking anywhere on the screen, reply to me and tell me to.
Here goes 1 hour:
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local selectionBox = workspace.Terrain:WaitForChild("Touch")
local locked = false
local lockedPart
local function onClick(target, boolean)
if target.Name == "Baseplate" then return end
if locked == false then
locked = true
lockedPart = nil
lockedPart = target
selectionBox.Adornee = target
selectionBox.SurfaceColor3 = Color3.new(0.631373, 0.537255, 1)
elseif locked == true then
if lockedPart == target then
locked = false
lockedPart = nil
else
return
end
end
end
task.spawn(function()
while wait() do
local Target = mouse.Target
if Target then
if selectionBox.Adornee ~= nil and Target ~= selectionBox.Adornee and locked == false then selectionBox.Adornee = nil end
local distance = (Target.Position - player.Character:WaitForChild("HumanoidRootPart").Position).Magnitude
if distance < 35 then
if locked == true then continue end
if Target.Name == "Baseplate" then continue end
locked = false
lockedPart = nil
selectionBox.Adornee = Target
selectionBox.Color3 = Color3.new(1, 0.415686, 0.415686)
selectionBox.SurfaceColor3 = Color3.new(1, 0.415686, 0.415686)
end
end
end
end)
mouse.Button1Down:Connect(function()
local Target = mouse.Target
onClick(Target, locked)
end)