Hey all, so lately iv’e been working on a classic styled building tool system that has a scale tool. But it is very buggy, and i just cant seem to get it fixed. These issues can be, welding problems, client and server differences, Scaling being able to move parts attached to it, and some other weird behaviors. Some help with fixing it or improving it will be very much appreciated!
Local Script
local tool = script.Parent.Parent
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local event = tool:WaitForChild("Event")
local lassoEvent = tool:WaitForChild("LassoEvent")
local removeEvent = tool:WaitForChild("RemoveEvent")
local clientEvent = tool:WaitForChild("ClientEvent")
local distanceEvent = tool:WaitForChild("ResetDistance")
local selectionBox = tool:WaitForChild("ScaleSelectionBox")
local handles = tool:WaitForChild("ScaleHandles")
local handlesClone
local clone
local selectedPart
local hum
local ToolSettings = tool:WaitForChild("BuildingSettings")
local PersonalPartsOnly = ToolSettings:WaitForChild("PersonalPartsOnly").Value
local db = false
function isOk(target)
if target and target:IsA("BasePart") and target.Locked == false then
if PersonalPartsOnly == true then
local Check = target:FindFirstChildOfClass("StringValue")
if Check and Check.Name == player.Name then
return true
end
else
return true
end
end
end
function renderStepped()
a = game:GetService("RunService").RenderStepped:Connect(function()
if isOk(mouse.Target) and clone then
clone.Adornee = mouse.target
end
end)
end
function drag()
b = handlesClone.MouseButton1Down:Connect(function()
distanceEvent:FireServer()
handlesClone.MouseDrag:Connect(function(norm, distance)
event:FireServer(handlesClone.Adornee, norm, distance)
end)
end)
end
tool.Equipped:Connect(function()
hum = tool.Parent:FindFirstChildOfClass("Humanoid")
handlesClone = handles:Clone()
handlesClone.Parent = player.PlayerGui
clone = selectionBox
clone.Parent = tool
if isOk(mouse.Target) then
clone.Adornee = mouse.target
end
drag()
renderStepped(clone)
end)
tool.Activated:Connect(function()
local target = mouse.Target
if isOk(target) and db == false then
db = true
if a then a:Disconnect() end
clone.Adornee = target
handlesClone.Adornee = target
lassoEvent:FireServer(target)
wait()
db = false
end
end)
tool.Deactivated:Connect(function()
removeEvent:FireServer()
end)
tool.Unequipped:Connect(function()
if a then a:Disconnect() end
if b then b:Disconnect() end
removeEvent:FireServer(true)
end)
clientEvent.OnClientEvent:Connect(function(part, ori, pos, welds)
if part then
part.Orientation = ori
part.Position = pos
for i = 1,#welds do
welds[i]:Clone().Parent = part
end
end
end)
Server Script
local tool = script.Parent.Parent
SizeLimit = 50
local event = tool:WaitForChild("Event")
local lassoEvent = tool:WaitForChild("LassoEvent")
local removeEvent = tool:WaitForChild("RemoveEvent")
local distanceEvent = tool:WaitForChild("ResetDistance")
local clientEvent = tool:WaitForChild("ClientEvent")
local previousDistance = 0
local lasso = Instance.new("SelectionPartLasso")
lasso.Color3 = Color3.fromRGB(216, 216, 0)
lasso.Transparency = 0
lasso.Visible = true
local db = false
local partt
local model
function isOk(target)
if target and target:IsA("BasePart") and target.Locked == false then
return true
else
return
end
end
function increment(part, normal, distance, resizeIncrement)
local delta = distance - previousDistance
if math.abs(delta) >= resizeIncrement then
local sizeDelta = math.floor(delta / resizeIncrement + 0.5) * resizeIncrement
if part:Resize(normal, sizeDelta) then
previousDistance = distance
end
end
end
distanceEvent.OnServerEvent:Connect(function()
previousDistance = 0
end)
event.OnServerEvent:Connect(function(plr, part, faceId, distance, resizeIncrement)
if part.Size.X >= SizeLimit then
part.Size = Vector3.new(SizeLimit - 1, part.Size.Y, part.Size.Z)
end
if part.Size.Y >= SizeLimit then
part.Size = Vector3.new(part.Size.X, SizeLimit - 1, part.Size.Z)
end
if part.Size.Z >= SizeLimit then
part.Size = Vector3.new(part.Size.X, part.Size.Y, SizeLimit - 1)
end
if part.Size.X < 1 then
part.Size = Vector3.new(1, part.Size.Y, part.Size.Z)
end
if part.Size.Y < 1 then
part.Size = Vector3.new(part.Size.X, 1, part.Size.Z)
end
if part.Size.Z < 1 then
part.Size = Vector3.new(part.Size.X, part.Size.Y, 1)
end
if part.Size.X < SizeLimit and part.Size.Y < SizeLimit and part.Size.Z < SizeLimit then
if part and part:IsA("BasePart") and part.Locked == false and db == false then
db = true
if part.Parent and part.Parent.Name and part.Parent.Name ~= "AAssAA" then
model = Instance.new("Model")
model.Name = "AAssAA"
model.Parent = workspace
part.Parent = model
end
if part.Anchored == false and not part:FindFirstChild("AnchorTag") then
local tag = Instance.new("BoolValue")
tag.Name = "AnchorTag"
tag.Parent = part
end
partt = part
part.Anchored = true
part:BreakJoints()
model:BreakJoints()
local resizeIncrement = part.ResizeIncrement
increment(part, faceId, distance, resizeIncrement)
if part.Parent.Name == "AAssAA" and model then
part.Parent = workspace
model:Destroy()
end
wait()
db = false
end
end
end)
lassoEvent.OnServerEvent:Connect(function(plr, target)
for i,v in pairs(workspace:GetChildren()) do
if v.Name == plr.Name .. " LASSO" then
v:Destroy()
end
end
if isOk(target) and plr.Character and plr.Character:FindFirstChild("Humanoid") then
local newLasso = lasso:Clone()
newLasso.Name = plr.Name .. " LASSO"
newLasso.Humanoid = plr.Character.Humanoid
newLasso.Part = target
newLasso.Parent = workspace
end
end)
removeEvent.OnServerEvent:Connect(function(plr, remLasso)
if partt then
model:MakeJoints()
partt:MakeJoints()
if partt:FindFirstChild("AnchorTag") then
partt.Anchored = false
end
local welds = {}
for i,v in pairs(partt:GetChildren()) do
if v:IsA("Weld") then
table.insert(welds, v)
end
end
clientEvent:FireClient(plr, partt, partt.Orientation, partt.Position, welds)
for i,v in pairs(workspace:GetChildren()) do
if v:IsA("BasePart") and v.Anchored == false then
local cWelds = {}
for i,c in pairs(v:GetChildren()) do
if c:IsA("Weld") then
table.insert(cWelds, c)
end
end
clientEvent:FireClient(plr, v, v.Orientation, v.Position, cWelds)
end
end
end
if remLasso == true then
for i,v in pairs(workspace:GetChildren()) do
if v.Name == plr.Name .. " LASSO" then
v:Destroy()
end
end
end
end)
here is a video showing the issues: https://youtu.be/xQgipW8PXoY