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

Could someone help me with attaching a motor6d to the UpperTorso as a Part0 when tools are equipped?

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)

1 answer

✓ Accepted answer

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)

2 comments

1

thank you!

0

no problem! :)

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