Hello there, I have an issue with my resize tool. It works perfectly when the part has a rotation of Vector3.new(0, 0, 0)
but as soon as it changes, it messes and does not resize as I wish.
1 - When there is no problems
Here, you can see that my part is being resized properly, note its orientation property.
https://gyazo.com/b934127a1c3538c9838a2fc2d74b1c8f
2 - When there are some issues
In this case, my part has an orientation ~= Vector3.new(0, 0, 0)
, and it does conflict with the current system, I have this as a result:
https://gyazo.com/a109b2b84290a8321b9c51ae1ea3df5f
3 - The script I used to make this system alive
Well, I don’t know how to explain my script. I am not using Basepart:Resize()
since I don’t know how to add an incrementation system with it. Instead, I am using the Part.Size
property, but you may know that when doing that, it resizes the part from its center. So, to fix this, I had to change the position of the part so as to have the desired system.
You can ask me some deeper pieces of information if you want (or need), here is the script:
(note that I tried my best to explain what I intended to do)
--[Varonex]--
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local commonS = PlayerGui:WaitForChild("Common") --All the handle adornments are stored in this
local rEvents = game.ReplicatedStorage:WaitForChild("rEvents")
local partComm = rEvents:WaitForChild("partInfoCommunicator") --RemoteEvent to transfer data to server
local sizeHandle = commonS:WaitForChild("sizeHandle") --The handler that is used to resize any part
local currentTool = script.Parent:WaitForChild("currentTool") --There are other tools such as rotate, ... but I removed useless parts
local selectedInstance = nil --Instance selected when clicking
local mouseOnAdornment = false --Is used to see if the mouse is on any adornment so as to prevent the part selection to fire
local tempInstance = nil --I don't remember what this variable is for but whatever
local moving = false
local resize = false
local rotate = false
local increment = script.Parent:WaitForChild("studs").Value --Incrementation, in studs
local degree = script.Parent:WaitForChild("degree").Value --Rotation, in degree
local Pos, sze, CF --Variables used to store stuff
local previousSizeDistance = 0 --I don't really know how to explain this one
--Convert NormalId
function convertNID(NormalId, part) --This is to convert the NormalId to the different vectors (LookVector, ...)
if NormalId == Enum.NormalId.Front then
return part.CFrame.LookVector, true
elseif NormalId == Enum.NormalId.Back then
return -part.CFrame.LookVector, false
elseif NormalId == Enum.NormalId.Right then
return part.CFrame.RightVector, true
elseif NormalId == Enum.NormalId.Left then
return -part.CFrame.RightVector, false
elseif NormalId == Enum.NormalId.Top then
return part.CFrame.UpVector, true
elseif NormalId == Enum.NormalId.Bottom then
return -part.CFrame.UpVector, false
end
end
function convertVectorLength(Vector) --Convert the Vector that we optained with the upper function with the only possibility to have 1 or 0 for each axis
if Vector.X and Vector.X ~=1 and Vector.X ~= 0 then
Vector = Vector3.new(1, Vector.Y, Vector.Z)
end
if Vector.Y and Vector.Y ~= 1 and Vector.Y ~= 0 then
Vector = Vector3.new(Vector.X, 1, Vector.Z)
end
if Vector.Z and Vector.Z ~= 1 and Vector.Z ~= 0 then
Vector = Vector3.new(Vector.X, Vector.Y, 1)
end
return Vector
end
--resize
sizeHandle.MouseButton1Down:Connect(function() --Store these pieces of information so as to make the resizer work properly
if selectedInstance ~= nil then
Pos = selectedInstance.Position
sze = selectedInstance.Size
end
end)
sizeHandle.MouseButton1Up:Connect(function() --Transfer the new size, ... to the server
if selectedInstance ~= nil then
partComm:FireServer("Size", selectedInstance, selectedInstance.Size.X, selectedInstance.Size.Y, nil, selectedInstance.Position.X, selectedInstance.Position.Y, nil)
end
end)
sizeHandle.MouseDrag:Connect(function(NormalId, distance)
print(NormalId, distance)
if selectedInstance ~= nil then
if increment ~= 0 then
distance = distance - (distance%increment)
end
if previousSizeDistance ~= distance then
local normalVector, ratio = convertNID(NormalId, selectedInstance) --Getting the vector from the NormalId
local vectorUnited = convertVectorLength(normalVector) --Making the upper vector with a length of 1 for each axis
selectedInstance.Size = sze + vectorUnited * distance --I am resizing the part from its center. So it growths on both sides
selectedInstance.Position = Pos + (vectorUnited * distance) / 2 --As we resize from the center, we have to reposition the half of the recize so as to
previousSizeDistance = distance
end
end
end)
--[Varonex]--
Note that the script is not fully put, some other functions are present but I decided to remove them since they don’t have any influence on the resize tool.
I have an idea of what can be the problem but I tried some other solutions that did not work. I guess it glitches since I am using LookVector
, UpVector
and RightVector
but I don’t really know what to do to fix that.
I tried to find some solutions on this forum, but they were either speaking about Basepart:Resize()
or had the same issue. I even tried to take some samples of solutions that was given here, but unfortunately the mistake is still present, even with this solution !
Thanks for having read this thread,
Varonex_0