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

how to change script from move tool to scale tool?

Asked by 2 years ago

i have this script for move tool (for placement system), when model is outside of base, it will be red and i wont be able to place it. i want scale tool for walls, floors. it will contain more parts in model and i have no idea how to even scale one part with scale tool script. can someone help me?

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 = script.Parent.Adornee.Parent.Parent.Parent.Parent
    if base then
        if (script.Parent.Adornee.Parent:SetPrimaryPartCFrame(cframe * CFrame.new(Vector3.FromNormalId(face)*distance))) ~= nil then
            script.Parent.Adornee.CFrame = script.Parent.Adornee.Parent:SetPrimaryPartCFrame(cframe * CFrame.new(Vector3.FromNormalId(face)*distance))
        end
        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) + Vector3.new(0, 1, 0))
        local max = ((base.Position + base.Size/2) + Vector3.new(0, 50, 0))
        local part1 = (ownmin.X <= max.X and ownmax.X <= max.X and ownmin.X >= min.X and ownmax.X >= min.X)
        local part2 = (ownmin.Z <= max.Z and ownmax.Z <= max.Z and ownmin.Z >= min.Z and ownmax.Z >= min.Z)
        local part3 = (ownmin.Y <= max.Y and ownmax.Y <= max.Y and ownmin.Y >= min.Y and ownmax.Y >= min.Y)
        if part1 and part2 and part3 then
            require(game:GetService("ReplicatedStorage").Placement):isColliding(script.Parent.Adornee.Parent, "Yes")
        elseif ownmin.X > max.X or ownmin.Z > max.Z or ownmin.Y > max.Y then
            script.Parent.Adornee.BrickColor = BrickColor.new("Really red")
        elseif ownmax.X > max.X or ownmax.Z > max.Z or ownmax.Y > max.Y then
            script.Parent.Adornee.BrickColor = BrickColor.new("Really red")
        elseif ownmin.X < min.X or ownmin.Z < min.Z or ownmin.Y < min.Y then
            script.Parent.Adornee.BrickColor = BrickColor.new("Really red")
        elseif ownmax.X < min.X or ownmax.Z < min.Z or ownmax.Y < min.Y then
            script.Parent.Adornee.BrickColor = BrickColor.new("Really red")
        end
    end
end)

Answer this question