im trying to make a script where it creates a motor6d when the tool is equipped, but im not sure how to make it attach to the UpperTorso as a Part0.
local tool = script.Parent local Char = game.Character tool.Equipped:Connect(function() local Motor6d = Instance.new("Motor6D",Char.UpperTorso) Motor6d.Name = "GunMotor6D" Motor6d.Part0 = Char.UpperTorso Motor6d.Part1 = tool.Handle end) tool.Unequipped:Connect(function() if Char.UpperTorso:FindFirstChild("GunMotor6D") then Char.UpperTorso.GunMotor6D:Destroy() end end)
Use a script in ServerScriptService, that's how I do it.
game.Players.PlayerAdded:Connect(function(plr) plr.CharacterAdded:Connect(function(char) local Motor6d = Instance.new("Motor6D") Motor6d.Parent = char:WaitForChild("UpperTorso") Motor6d.Name = "GunMotor6D" Motor6d.Part0 = char.UpperTorso end) end)
Then when the tool is equipped:
local tool = script.Parent local Char local Motor6d tool.Equipped:Connect(function() Char = tool.Parent Motor6d = Char.UpperTorso:WaitForChild("GunMotor6D") Motor6d.Part1 = tool.Handle end) tool.Unequipped:Connect(function() if Motor6d then Motor6d.Part1 = nil end end)