Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I am setting a new part's position to the character's left arm's position, but it lags behind?

Here's my code:

local LeftArmHitbox = Instance.new("Part")
LeftArmHitbox.Parent = workspace
LeftArmHitbox.CanCollide = false
LeftArmHitbox.Anchored = true
LeftArmHitbox.Material = "ForceField"
LeftArmHitbox.Size = Vector3.new(2, 3, 2)

while true do
	LeftArmHitbox.Position = script.Parent:FindFirstChild("Left Arm").Position
	LeftArmHitbox.Orientation = script.Parent:FindFirstChild("Left Arm").Orientation
	wait()
end

When i try to remove wait(), the "while,do" statement times out. When I keep it there, the part lags behind whenever I move. Any suggestions?

1 answer

Use attachments for it here try using this code

local attachArm = Instance.new("Attachment")
attachArm.Visible = false
attachArm.Name = attachArm
attachArm.Parent = --here add the name of part 1 like your left arm if you want the other part to come towards your left arm
attachArm.Position = --again it depends on your needs if you want other part to come at arms center then use attachArm.Parent.Position otherwise if you want it a lil bit here and there add a vector 3 value to it like attachArm.Parent.Position + vector3.new(1,1,0)

--here we will add attachment to your part which you wanna move towards the arm

local attachpart = Instance.new("Attachment")
attachpart.Visible = false
attachpart.Parent = --The Part Wich You Want To Move Towards Arm (add its whole path)
--We dont Want Position Here also now heres main thing

local alignposition = Instance.new("AlignPosition")
alignPosition.MaxForce = 25000
alignPosition.Attachment0 = attachArm --make sure its attacharm or your arm will move to the part
alignPosition.Attachment1 = attachpart
alignPosition.Responsiveness = --the more responsiveness you give the more it will move faster with your arm above 50 is just like its stuck to your arm
alignposition.Parent = attachPart.Parent

-- now after this is if you dont want your part to be rolling with gravity in mid air if you dont do this the part will just move with you but it will not be oriented it will be rolling in mid air at same spot

local alignOrientation = Instance.new("AlignOrientation")
alignOrientation.MaxTorque = 25000
alignOrientation.Attachment0 = attachArm
alignOrientation.Attachment1 = attachpart
alignOrientation.Responsivness = --same as alignPosition responsivness
alignOrientation.Parent = attachpart.Part

--There you are done just add some functions to execute this code and it will be working just make sure that your part is aldready in workspace or spawn it in before this code runs you will be done!!!


1 comment

0

Thanks for the answer, but there were a lot of errors when I used this code. Can you please edit your script a little bit?

This discussion is preserved as it was. New answers, comments, and votes are closed.