AlignPosition is sometimes a different position

Hello everyone! I am writing a carrying system and have basically finished it, but for some reason when the player is being carried, the alignpositions and attachments are somewhat off each time, and other times they’re perfect, its just a weird bug and I have pictures describing what is happening here:
WRONGONE

Both pictures were taken like 5 seconds apart but I have no idea what the issue could possibly be, here is the code I used to make the Attachments/AlignPosition:

AcceptedRequest.OnServerEvent:Connect(function(plr, requesterName)

	-- REQUESTER = Carrier
	-- plr = Player being Carried


	local requester = Players[requesterName]
	
	print(CarryingPlayer[requester])

	if CarryingPlayer[requester] then return end

	local value = Instance.new("StringValue")
	value.Value = requesterName
	value.Parent = plr.Character

	CarryPlayer:FireClient(requester, "Carry")
	CarryPlayer:FireClient(plr, "BeingCarried")

	CarryingPlayer[requester] = true

	local AlignPosition = Instance.new("AlignPosition")
	AlignPosition.RigidityEnabled = true
	AlignPosition.Responsiveness = 100
	
	local Attach0 = Instance.new("Attachment")
	local Attach1 = Instance.new("Attachment")

	Attach0.Name = "PLAYER"
	Attach1.Name = "REQUESTER"

	local AlignOrientationBRUH = Instance.new("AlignOrientation")
	AlignOrientationBRUH.Name = "YUH"

	AlignOrientationBRUH.RigidityEnabled = true
	AlignOrientationBRUH.Parent = plr.Character.HumanoidRootPart
	AlignOrientationBRUH.Attachment0 = Attach0
	AlignOrientationBRUH.Attachment1 = Attach1

	Attach0.Parent = plr.Character.HumanoidRootPart
	Attach1.Parent = requester.Character.Head

	Attach0.WorldPosition = plr.Character.HumanoidRootPart.Position
	Attach1.WorldPosition = requester.Character.Head.Position + Vector3.new(0.8, 1, 0)

	AlignPosition.Attachment0 = Attach0
	AlignPosition.Attachment1 = Attach1

	plr.Character.HumanoidRootPart:SetNetworkOwner(requester)

	SetCollisionGroupON(plr.Character)

	AlignPosition.Parent = plr.Character.HumanoidRootPart
end)

I would guess it’s from how the attachments are being created on the server, but the characters are being controlled on the client.

I would first try using the Attachment.Position property (which is relative to the parts) instead of Attachment.WorldPosition.

The other potential problem is that you add an offset to a world position that’s not relative to the orientations of the parts:

Attach1.WorldPosition = requester.Character.Head.Position + Vector3.new(0.8, 1, 0)

This means the x offset of 0.8 goes in different directions relative to the characters depending on which way they’re facing. You can fix this by making this offset character relative:

-- Use something like this to convert from character relative to world relative
characterHRPCFrame:VectorToWorldSpace(Vector3.new(0.8, 1, 0))
1 Like

Thanks bro I knew I was missing something, I forgot about relative positions and such and this code right here worked:

	Attach0.WorldPosition = plr.Character.HumanoidRootPart.Position
	Attach1.WorldPosition = requester.Character.Head.Position + requester.Character.Head.CFrame:VectorToWorldSpace(Vector3.new(0, 1, 1))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.