Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

SelectionBox and ClickDetectors not being removed?

I came across another problem working with the code, no errors show though. I don't see any problem either.

Here's the code:

local tool = script.Parent

local mychar
local myhum
local chosen = false

tool.Equipped:connect(function()
    mychar = tool.Parent
    myhum = mychar:WaitForChild("Humanoid")
    myhum.WalkSpeed = 0
    hold = myhum:LoadAnimation(tool:WaitForChild("Hold"))

    hold:Play()

    for _,part in pairs(workspace:GetChildren()) do
        if part:IsA("Part") then
        if (part.Position - mychar.Torso.Position).Magnitude <= 12 then
                local box = Instance.new("SelectionBox", part)
                box.Adornee = part
                box.Color3 = Color3.new(255, 170, 0)
                local click = Instance.new("ClickDetector", part)
                click.MouseClick:connect(function()
                    tool.Handle.Anchored = true
                    tool.Handle.Rotation = Vector3.new(0, 0, 0)
                    tool.Handle.Parent = workspace
                    workspace.Handle.Name = mychar.Name.."_"..tool.Name
workspace:FindFirstChild(mychar.Name.."_"..tool.Name).Position = part.Position + Vector3.new(0, part.Size.Y, 0)
                    chosen = true
	box:Destroy()
	click:Destroy()
          end)
    end
    end
    end
end)

tool.Unequipped:connect(function()
    hold:Stop()
    myhum.WalkSpeed = 16
end)

1 answer

I'm pretty sure you need to set variables as you enter them or it will error... Check your output.

This discussion is preserved as it was. New answers, comments, and votes are closed.