Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)

1
thank you! XxAgarioHeroxX338455 5 — 4y
0
no problem! :) Utter_Incompetence 856 — 4y
Ad

Answer this question