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.
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)