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

move tool can still move part outside of borders, how to fix it?

Asked by 2 years ago

im using this script in placement system and i want to be able move parts with it only in base and not outside.

local cframe = CFrame.new()
script.Parent.MouseButton1Down:Connect(function()
    cframe = script.Parent.Adornee.CFrame
end)

script.Parent.MouseDrag:Connect(function(face, distance)
    distance = math.round(distance/1) * 1
    local base = game.Workspace.shops.Base1
    local ownmin = (script.Parent.Adornee.Position - script.Parent.Adornee.Size/2)
    local ownmax = (script.Parent.Adornee.Position + script.Parent.Adornee.Size/2)
    local min = (base.Position - base.Size/2)
    local max = (base.Position + base.Size/2)
    if ownmin.X < max.X and ownmax.X < max.X and ownmin.X > min.X and ownmax.X > min.X then -- this works if it move slow but dont if fast
        script.Parent.Adornee.CFrame = cframe * CFrame.new(Vector3.FromNormalId(face)*distance)
    end
end)

script.Parent.Parent.MoveTest.MouseButton1Click:Connect(function()
    script.Parent.Adornee.Position = Vector3.new(1042.463, 714, -3277.23)
end)

Answer this question