Hello, I have a semi functional armor welding system. I have one set of armor that welds perfectly and I have one set that for some odd reason does not want to orientate itself correctly. Heres some images/gifs below:
Correct Welding: https://gyazo.com/cbdad2f215d234e56e16c3caad16253e
Incorrect welding issue: https://gyazo.com/8d139da64517cbdbbd1ba9815136e731
Correct:
Incorrect:
I have both armors in the exact same spot, in the exact same orientations
There are no errors printing either. No matter what I rotate the parts to or set the orientation at, it will go back to the exact same orientation. Any help or support would be greatly appreciated!
Welding server code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUIFunctions = require(ReplicatedStorage:WaitForChild("GUIFunctions"))
local EventsFolder = ReplicatedStorage:FindFirstChild("Events")
local function CreateErrorNotifcation(Player)
GUIFunctions.CreateArmorErrorNotification(Player)
end
local EquipArmorRemoteEvent = EventsFolder:FindFirstChild("EquipArmor")
local UnequipArmorRemoteEvent = EventsFolder:FindFirstChild("UnequipArmor")
local ServerScriptService = game:GetService("ServerScriptService")
local AdminModule = require(ServerScriptService.Admins)
local ArmorsFolder = ServerScriptService:FindFirstChild("Armor")
local Workspace = game:GetService("Workspace")
local SafeZonesFolder = Workspace:WaitForChild("Safezones")
local ItemInfoModule = require(ServerScriptService.ItemInfo)
-- Table to store the original accessories of each player
local safeZoneRegions = {} -- Stores all Safe Zone regions
local safeZoneParts = {} -- Stores actual safe zone parts
-- Function to create Safe Zone regions dynamically
local function createSafeZoneRegions()
for _, part in ipairs(SafeZonesFolder:GetChildren()) do
if part:IsA("BasePart") and part.Name == "Safezone" then
local size = part.Size
local position = part.Position
-- Store the actual part for direct position checks
table.insert(safeZoneParts, part)
-- Define the Region3 with extra height
local region = Region3.new(
position - (size / 2) + Vector3.new(0, -5, 0), -- Extend downward slightly
position + (size / 2) + Vector3.new(0, 20, 0) -- Extend upward for better coverage
)
table.insert(safeZoneRegions, region)
end
end
end
local function isPlayerInSafeZone(player)
local character = player.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
for _, part in ipairs(safeZoneParts) do
local size = part.Size
local position = part.Position
-- Check if player is inside the Safezone using bounding box calculations
local minBound = position - (size / 2) + Vector3.new(0, -5, 0)
local maxBound = position + (size / 2) + Vector3.new(0, 20, 0)
local playerPos = rootPart.Position
if (playerPos.X >= minBound.X and playerPos.X <= maxBound.X) and
(playerPos.Y >= minBound.Y and playerPos.Y <= maxBound.Y) and
(playerPos.Z >= minBound.Z and playerPos.Z <= maxBound.Z) then
return true
end
end
end
end
return false
end
createSafeZoneRegions()
local function changeAccessoryTransparency(character, transparency)
local accessories = character:GetChildren()
for _, accessory in ipairs(accessories) do
if accessory:IsA("Accessory") then
local handle = accessory:FindFirstChild("Handle")
if handle and handle:IsA("BasePart") then
handle.Transparency = transparency
end
end
end
end
local function CreateWeld(Part0, Part1)
local weld = Instance.new("Weld")
weld.Name = "ArmorWeld"
weld.Parent = Part0
weld.Part0 = Part0
weld.Part1 = Part1
Part0.CFrame = Part1.CFrame
if Part1.Name == "Left Arm" or Part1.Name == "Right Arm" then
local armorInfo = ItemInfoModule[Part0.Parent.Parent.Name]
local c0PositionValues = armorInfo.ArmPosition:split(", ")
local c0Position = Vector3.new(
tonumber(c0PositionValues[1]),
tonumber(c0PositionValues[2]),
tonumber(c0PositionValues[3])
)
weld.C0 = CFrame.new(c0Position)
elseif Part1.Name == "Head" then
local armorInfo = ItemInfoModule[Part0.Parent.Parent.Name]
local c0PositionValues = armorInfo.HeadPosition:split(", ")
local c0Position = Vector3.new(
tonumber(c0PositionValues[1]),
tonumber(c0PositionValues[2]),
tonumber(c0PositionValues[3])
)
weld.C0 = CFrame.new(c0Position)
elseif Part1.Name == "UpperTorso" then
local armorInfo = ItemInfoModule[Part0.Parent.Parent.Name]
local c0PositionValues = armorInfo.TorsoPosition:split(", ")
local c0Position = Vector3.new(
tonumber(c0PositionValues[1]),
tonumber(c0PositionValues[2]),
tonumber(c0PositionValues[3])
)
weld.C0 = CFrame.new(c0Position)
end
end
local function weldParts(PlayerLimb, ArmorLimb)
if ArmorLimb and PlayerLimb then
if ArmorLimb:IsA("Model") then
for _, Part in pairs(ArmorLimb:GetDescendants()) do
if Part:IsA("BasePart") then
--if Part.Name == "Chest"or "Limb" then
CreateWeld(Part, PlayerLimb)
--elseif Part:IsA("UnionOperation") then
-- CreateWeld(ArmorLimb, PlayerLimb)
-- elseif Part:IsA("MeshPart") then
-- CreateWeld(ArmorLimb, PlayerLimb)
end
end
end
end
end
local function equipClothesToPlayer(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local clothing = player.Character:FindFirstChild("Clothing")
if clothing then
local playerClothes = clothing:GetChildren()
for _, part in ipairs(playerClothes) do
if part:IsA("BasePart") then
part.Transparency = 0
end
end
end
end
end
end
local function unequipClothesToPlayer(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local clothing = player.Character:FindFirstChild("Clothing")
if clothing then
local playerClothes = clothing:GetChildren()
for _, part in ipairs(playerClothes) do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
end
end
end
end
local function equipArmorToPlayer(player, armor)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local armormodel = armor:Clone()
armormodel.Parent = character.ArmorHolder
unequipClothesToPlayer(player)
local armormodelparts = {
ArmorHead = armormodel:FindFirstChild("ArmorHead"),
ArmorLeftArm = armormodel:FindFirstChild("ArmorLeftArm"),
ArmorRightArm = armormodel:FindFirstChild("ArmorRightArm"),
ArmorLeftLeg = armormodel:FindFirstChild("ArmorLeftLeg"),
ArmorRightLeg = armormodel:FindFirstChild("ArmorRightLeg"),
ArmorTorso = armormodel:FindFirstChild("ArmorTorso"),
}
local PlayerLimbs = {
PlayerHead = character:WaitForChild("Head"),
PlayerLeftArm = character:WaitForChild("Left Arm"),
PlayerRightArm = character:WaitForChild("Right Arm"),
PlayerLeftLeg = character:WaitForChild("Left Leg"),
PlayerRightLeg = character:WaitForChild("Right Leg"),
PlayerTorso = character:WaitForChild("UpperTorso"),
}
for armorPartName, armorPart in pairs(armormodelparts) do
local playerPart = PlayerLimbs[string.gsub(armorPartName, "Armor", "Player")]
if armorPart and playerPart then
weldParts(playerPart, armorPart)
end
end
end
end
end
local function RemoveLimbs(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
end
end
end
local function RestoreLimbs(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
for _, part in ipairs(character:GetDescendants()) do
if part:IsA("BasePart") then
if part.Name ~= "Torso" and part.Name ~= "HumanoidRootPart" then
part.Transparency = 0
end
end
end
end
end
end
EquipArmorRemoteEvent.OnServerEvent:Connect(function(player, armor)
if not isPlayerInSafeZone(player) then
CreateErrorNotifcation(player)
return
end
local armormodel = ArmorsFolder:FindFirstChild(armor)
local PlayerSettings = player:FindFirstChild("PlayerSettings")
local leaderstats = player:FindFirstChild("leaderstats")
local PlayerLevel = leaderstats:FindFirstChild("Level")
local ArmorSelected = PlayerSettings:FindFirstChild("ArmorSelected")
local Admin = PlayerSettings:FindFirstChild("Admin")
local PlayerSavesFolder = player:FindFirstChild("PlayerSaves")
local PlayerSettingsFolder = player:FindFirstChild("PlayerSettings")
local PlayerSelectedSlot = PlayerSavesFolder:FindFirstChild(PlayerSettingsFolder.SelectedSave.Value)
local armormodel = ArmorsFolder:FindFirstChild(armor)
if armormodel then
if ArmorSelected.Value == "" then
if PlayerSelectedSlot.PlayerItems:FindFirstChild(armor).Value >= 1 then
if PlayerLevel.Value >= ItemInfoModule[armor].Level then
if ItemInfoModule[armor].Admin == false and ItemInfoModule[armor].Skin == false then
unequipClothesToPlayer(player)
ArmorSelected.Value = armor
equipArmorToPlayer(player, armormodel)
local ArmorHealth = ItemInfoModule[armor].Health
player.Character.Humanoid.MaxHealth = ArmorHealth
elseif ItemInfoModule[armor].Admin == false and ItemInfoModule[armor].Skin == true then
if PlayerSelectedSlot.PlayerItems:FindFirstChild(armor).Value >= 1 then
print("Skin Armor")
RemoveLimbs(player)
ArmorSelected.Value = armor
equipArmorToPlayer(player, armormodel)
local ArmorHealth = ItemInfoModule[armor].Health
player.Character.Humanoid.MaxHealth = ArmorHealth
else
end
elseif ItemInfoModule[armor].Admin == true then
if PlayerSelectedSlot.PlayerItems:FindFirstChild(armor).Value >= 1 then
print("Admin Armor")
if Admin.Value == true then
ArmorSelected.Value = armor
equipArmorToPlayer(player, armormodel)
local ArmorHealth = ItemInfoModule[armor].Health
player.Character.Humanoid.MaxHealth = ArmorHealth
player.Character.Humanoid.Health = ArmorHealth
else
end
else
end
end
end
else
print("Level not high enough")
end
end
end
end)
UnequipArmorRemoteEvent.OnServerEvent:Connect(function(player)
local character = player.Character
local PlayerSettings = player:FindFirstChild("PlayerSettings")
local ArmorSelected = PlayerSettings:FindFirstChild("ArmorSelected")
if ArmorSelected.Value ~= "" then
equipClothesToPlayer(player)
RestoreLimbs(player)
local PlayerArmor = player.Character.ArmorHolder:FindFirstChild(ArmorSelected.Value)
PlayerArmor:Destroy()
ArmorSelected.Value = ""
player.Character.Humanoid.MaxHealth = 100
player.Character.Humanoid.Health = 100
end
end)