My Character stutters whenever i Weld parts to it

Whenever a character equips a tool, i run this script:

local EquipHandle = function(Character, Handles) -- Handles is a folder inside the tool
	
	for _, Handle in ipairs(Handles:GetChildren()) do -- Handle is a model
		
		local ModelMainPart = Handle.PrimaryPart
		-- BodyPart is RightHand/LeftHand
		local BodyPart = Character[ModelMainPart.WeldConstraint:GetAttribute("Part1")]
		ModelMainPart.CFrame = BodyPart.CFrame
		ModelMainPart.WeldConstraint.Part1 = BodyPart -- I weld the model's primary part to the hand
		
	end
	
end

Tool.Equipped:Connect(function()
				
		if Handles then -- Handles is a folder inside the tool
			
			EquipHandle(Character,Handles)
			
		end

end)

This script works, the only problem is that whenever i equip the tool, my character “stutters”. I’m pretty sure this has something to do with this line but idk

ModelMainPart.CFrame = BodyPart.CFrame

Btw the parts in the model have -2 root priority and -1 in the primary part(not sure if this is necessary), the player has network ownership of them, and they’re massless.

robloxapp-20231024-1551369.wmv (872.6 KB) idk a better way to show the stutter

1 Like

i dont know if this would help, but have you tried setting the network ownership of the tool

1 Like

No, that doesn’t seem to be the problem. Seems like good practice tho, so thanks for telling me about it

Are the Parts/Meshes set to Massless in the Properties? Any mass added to a player affects their physics.

2 Likes

They’re massless. Bla bla bla bla character limit

have you tried running this on a localscript

1 Like

i dont know if this has a fix. ive encountered this before with physical projectiles, and it looks normal on the serverside

1 Like

I can’t do that since i need to have access to those parts on the server. But it works on the client tho.

Update: It does not work on the client

The stuttering affect’s the Character’s physics on the client, and replicates it to the server.

Not sure if this has anything to do with it, but why are you equipping the tool, then looping through a folder searching for the Handle PrimaryPart?
You should only have one item named Handle in the tool, and the tool shouldn’t be named Handle.

If you are welding specific models with specific name to the character’s hands why not just use the names of the models inside the folder, instead of calling everything Handle and searching through everything in the folder?

So i can have more control over how the handle looks and the amount of “handles” i have.

I’m using the Dry principle, this function works with any tool that i create, i don’t have to make a specific script for it. the Variable Handle stands for any model i want to put in a tool’s Handles folder

This turned out to be the only way to do this (with :FireAllClients). I was apprehensive at first but i noticed that the local script doesn’t really change the Part’s parents, so any changes made to it in the server would still replicate.

RemoteEvents.EquipHandles.OnClientEvent:Connect(function(Handles, Character)
	for _, Handle in ipairs(Handles:GetChildren()) do
		local ModelMainPart = Handle.PrimaryPart
		local BodyPart = Character[ModelMainPart.WeldConstraint:GetAttribute("Part1")] 
		ModelMainPart.CFrame = BodyPart.CFrame
		ModelMainPart.WeldConstraint.Part1 = BodyPart
	end
end)

In the server:

Tool.Equipped:Connect(function()		
		if Handles then
			ReplicatedStorage.RemoteEvents.VisualEffects.EquipHandles:FireAllClients(Handles, Character)	
		end
end)
	
Tool.Unequipped:Connect(function()		
	if Handles then
		for _, Handle in ipairs(Handles:GetChildren()) do
			Handle.PrimaryPart.Anchored = true -- Also i learned you should Anchor it on the server and Unanchor in the client, else it falls and is destroyed
		end
	end
end)

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