I have two issues with a custom resize tool I would like to address in this post.
1: my tool resizes the wrong direction when rotated.
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)
the problem occurs when dragging the handles. if a part has not been rotated, resizing the part works just fine, dragging left causes the part to resize to the left,etc.
if the part has been rotated recently, resizing the part resizes in the wrong direction. dragging one direction may cause the part to resize sideways or in the opposite direction.why is this occurring?
2: remote events hit the spam limit too often.
I came upon this problem only recently, in the script above, a remote event is fired and provides key information such as part name,its cframe,size, etc. but when a player resizes a part fast enough this happens:
after waiting I checked to see if this still happened and I could only resize 3 or 4 times before this happens again, why is this happening? is what Im sending through the remote event too much?