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

resize tool resizes in an odd way?

Asked by 4 years ago

I have a resize tool:

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
enabled = true
local selectionBox
local selectionLasso
local handles
local previousDistance
local originalpart
local buttonupconnection
local tempart
local increment = 0.5
local originalcf, originalsize




local AxisSizeMultipliers = {
    [Enum.NormalId.Top] = Vector3.new(0, 1, 0);
    [Enum.NormalId.Bottom] = Vector3.new(0, 1, 0);
    [Enum.NormalId.Front] = Vector3.new(0, 0, 1);
    [Enum.NormalId.Back] = Vector3.new(0, 0, 1);
    [Enum.NormalId.Left] = Vector3.new(1, 0, 0);
    [Enum.NormalId.Right] = Vector3.new(1, 0, 0);
}


local AxisPositioningMultipliers = {
    [Enum.NormalId.Top] = Vector3.new(0, 1, 0);
    [Enum.NormalId.Bottom] = Vector3.new(0, -1, 0);
    [Enum.NormalId.Front] = Vector3.new(0, 0, -1);
    [Enum.NormalId.Back] = Vector3.new(0, 0, 1);
    [Enum.NormalId.Left] = Vector3.new(-1, 0, 0);
    [Enum.NormalId.Right] = Vector3.new(1, 0, 0);
}




function onHandlesDown(normal)
    originalcf = handles.Adornee.CFrame
    originalsize = handles.Adornee.Size
    previousDistance = 0
end



function onHandlesDrag(normal, distance)
    if handles.Adornee then
        distance = distance - (distance%increment)
        handles.Adornee.Size = originalsize + AxisSizeMultipliers[normal] * distance
        handles.Adornee.CFrame = originalcf + (AxisPositioningMultipliers[normal] * distance) / 2

            if handles.Adornee then
                previousDistance = distance
                --send changes to server
                buttonupconnection = mouse.Button1Up:connect(function()onButton1Up(mouse,handles.Adornee)end)
    --
        end
    end
end




function onButton1Up(mouse,part)
    if part and script.Parent.Parent == plr.Character then
    local size = part.Size
    local cfr = part.CFrame
    script.Parent.PartChange:FireServer(originalpart,size,cfr)
    end
end




function onButton1Down(mouse)
    local findpart = game.ReplicatedStorage.BuildingParts:FindFirstChild(mouse.Target.Name)
    if tempart then
        tempart:Destroy()
        end
    if mouse.Target == nil or mouse.Target.Locked or not findpart then
        print("nil")
        selectionBox.Adornee = nil
        selectionLasso.Part = nil
        handles.Adornee = nil
    else
        print("not nil")
        originalpart = mouse.Target
        tempart = findpart:Clone()
        tempart.CanCollide = false
        tempart.Anchored = true
        tempart.Transparency = 0.6
        tempart.Size = originalpart.Size
        tempart.Parent = game.Workspace
        tempart.CFrame = originalpart.CFrame
        tempart.BrickColor = BrickColor.new("Lime green")
        selectionBox.Adornee = tempart
        selectionLasso.Part = tempart
        handles.Adornee = tempart
        handles.Faces = tempart.ResizeableFaces
    end
end




function onEquippedLocal(mouse)
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)

    local character = script.Parent.Parent
    local player = game.Players:GetPlayerFromCharacter(character)

    selectionBox = Instance.new("SelectionBox")
    selectionBox.Color = BrickColor.Blue()
    selectionBox.Adornee = nil
    selectionBox.Parent = player.PlayerGui

    selectionLasso = Instance.new("SelectionPartLasso")
    selectionLasso.Name = "Model Delete Lasso"
    selectionLasso.Humanoid = character.Humanoid
    selectionLasso.Parent = game.workspace
    selectionLasso.Part = nil
    selectionLasso.Visible = true
    selectionLasso.archivable = false
    selectionLasso.Color = BrickColor.Red()

    handles = Instance.new("Handles")
    handles.Color = BrickColor.Blue()
    handles.Adornee = nil
    handles.MouseDrag:connect(onHandlesDrag)
    handles.MouseButton1Down:connect(onHandlesDown)
    handles.Parent = player.PlayerGui
end

function onUnequippedLocal()
    selectionBox:Destroy()
    selectionLasso:Destroy()
    handles:Destroy()
    if handles.Adornee then
        handles.Adornee:Destroy()
    end
    if buttonupconnection then
    buttonupconnection:Disconnect()
    end
end


tool.Equipped:connect(onEquippedLocal)
tool.Unequipped:connect(onUnequippedLocal)

but I noticed something odd, when I resize a tool that has not been recently rotated, it resizes in the direction of the handle thats being dragged as expected, however the part was rotated, the part resizes in the wrong direction, why is this?

0
well i'm gonna read your 150 line script Luka_Gaming07 534 — 4y
0
You don't wanna use Player:GetMouse() anymore, Use UserInputService Instead Luka_Gaming07 534 — 4y
0
Also SelectionPartLasso is deprecated Luka_Gaming07 534 — 4y
0
i cannot give you an answer Luka_Gaming07 534 — 4y
0
depreciated items can be taken care of, however that doesnt solve my current dilemma. mantorok4866 201 — 4y

Answer this question