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

SelectionBox and ClickDetectors not being removed?

Asked by
wackem 50
8 years ago

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

Log in to vote
0
Answered by
snow29 0
8 years ago

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

Ad

Answer this question