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

Why does the tool's 6 points become scatted on-equip?

This occurs whether I make the welds before the tool is equipped, or during the equip of the tool.

There are 8 parts in all, two are welded onto the arms as gauntlets (This works perfectly fine). Then, I have 6 parts which are invisible and will be used as points for the start of a raycast 'bullet' when shooting. This works as well, I just can't really use it because the point is scattered for some odd reason when you equip and is welded away from the tool. The parts are already placed on the correct spot of the tool and I'm not sure if it matters but the position of the 6 parts were moved without a grid (Not 1 stud, not 1/5th of a stud). They are also CanCollide = false so physics shouldn't be causing them to be a distance away from the character .

Here is the welding script inside of the tool;

local Tool = script.Parent.Parent
local Plr = game.Players.LocalPlayer
repeat wait() until Plr.Character
local Char = Plr.Character
local LArm = Char:WaitForChild("Left Arm")
local RArm = Char:WaitForChild("Right Arm")
local Hum = Char:WaitForChild("Humanoid")
local Claw = Tool.LClaw

local Equip = Instance.new("Animation")
Equip.AnimationId = "rbxassetid://335140780" 
Equip.Name = "EP"

local Collect = script.Parent.Parent:GetChildren()
local WeldPart = script.Parent.Parent.Handle
local WeldPart2 = Claw
local NotDone = false

if NotDone == false then NotDone = true
	for _, part in pairs(Collect) do
		if part:IsA("BasePart") then	
			if part.Name ~= WeldPart.Name and part.Name ~= WeldPart2.Name then
				if part.Name == "lbottom" or part.Name == "lmiddle" or part.Name == "ltop" then
					local Weld = Instance.new("Weld", WeldPart2)
					Weld.Name = part.Name
					Weld.Part0 = WeldPart2
					Weld.Part1 = part
					Weld.C0 = Weld.Part0.CFrame:inverse()
					Weld.C1 = Weld.Part1.CFrame:inverse()
				elseif part.Name == "Bottom" or part.Name == "Middle" or part.Name == "Top" then
					local Weld = Instance.new("Weld", WeldPart)
					Weld.Name = part.Name
					Weld.Part0 = WeldPart
					Weld.Part1 = part
					Weld.C0 = Weld.Part0.CFrame:inverse()
					Weld.C1 = Weld.Part1.CFrame:inverse()
				end
			end
		end
	end
end

Tool.Equipped:connect(function()
	local ETrack = Hum:LoadAnimation(Equip)
	ETrack:Play()
	ETrack:AdjustSpeed(0)
	
	Tool.Unequipped:connect(function()
		ETrack:Stop()
	end)
	
	if not Tool:WaitForChild("Handle"):FindFirstChild("Weld") then
		for _ , Part in pairs(Tool:GetChildren()) do
			if Part.Name == "LClaw" then
				Part.CFrame = LArm.CFrame
				
				local WeldPart0 = LArm
				local Weld = Instance.new("Weld", WeldPart0)
				
				Weld.Name = Part.Name
				Weld.Part0 = WeldPart0
				Weld.Part1 = Part
				Weld.C0 = CFrame.new(-0.05,-.8,0) * CFrame.Angles(0, math.rad(180), 0)
			end
		end
	end
end)

1 answer

You should anchor the parts in the tool before welding it, otherwise physics can affect the components before they are stuck together. You should also weld the tool in another script separate from the one handling code (better yet, weld it in studio instead of doing it for every new instance of the tool.)

edit: on line 55 you're setting LClaw.CFrame, breaking all of its welds. You don't need to do that.

Tool script:

local Tool=script.Parent.Parent
local Plr=game.Players.LocalPlayer
local Char=Plr.Character or Plr.CharacterAdded:wait()
local LArm=Char:WaitForChild("Left Arm")
local Hum=Char:WaitForChild("Humanoid")

local Equip=Instance.new("Animation")
Equip.AnimationId="rbxassetid://335140780" 
Equip.Name="EP"

local ETrack;
Tool.Equipped:connect(function()
	ETrack=Hum:LoadAnimation(Equip)
	ETrack:Play()
	ETrack:AdjustSpeed(0)
	local w=Instance.new("Weld",LArm)
	w.Part0=LArm
	w.Part1=Tool.LClaw
	w.C0=CFrame.new(-.05,-.8,0)*CFrame.Angles(0,math.pi,0)
end)
Tool.Unequipped:connect(function()
	if ETrack then
		ETrack:Stop()
	end
end)

Weld script:

local Tool=script.Parent.Parent
function Weld(a,b)
	local w=Instance.new("Weld",a)
	w.Part0=a
	w.Part1=b
	w.C0=a.CFrame:inverse()*b.CFrame
end
Weld(Tool.LClaw,Tool.lbottom)
Weld(Tool.LClaw,Tool.lmiddle)
Weld(Tool.LClaw,Tool.ltop)
Weld(Tool.Handle,Tool.Bottom)
Weld(Tool.Handle,Tool.Middle)
Weld(Tool.Handle,Tool.Top)
for _,v in pairs(Tool:GetChildren())do
	if v:IsA("BasePart")then
		v.Anchored=false
	end
end

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