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

[SOLVED] Motor6D not working properly in tool animation?

Asked by 1 year ago
Edited by imKirda 1 year ago

What it's meant to look like: https://streamable.com/4g7j5o

What it looks like in-game: https://streamable.com/roxi4p

I'm using Nilociety's Motor6D fix script for tool animations, and I've followed every step to the best of my knowledge, but it isn't working. Here is their post: https://devforum.roblox.com/t/how-to-animate-tool-handles-easily-specifically-melees-unsure-of-guns/921518

My version of the code:

-- You want to reference the BoolValue, the Motor6D, AND the name of your tool.
local Tool = script.Parent
local MotorCheck = script.MotorCheck
local Motor6D = script.Motor6D

-- NEW ATTRIBUTES FOR ATTACHING TO A BODY PART! CHANGE THE ATTRIBUTE TO MAKE THE SCRIPT ATTACH TO THAT PART! --
local ToolPartName = script:GetAttribute("Tool_Part_Name")
local BodyPartName = script:GetAttribute("Body_Part_Name")

-- Put an empty variable for finding the RightArmGrip
local RightArmGrip

--[[
You want to call a function to Attach the Motor6D's to the specified part on this
scripts "Tool_Part_Name" attribute found in Properties. Make sure when you input the name,
the name is the EXACT SAME NAME as the name of the Tools handle name. If you wish to not use Attributes for this, and to support
more than 1 Motor6D, please remove "Tool:WaitForChild(ToolPartName)" and replace it with just the name of your tool.
]]

Tool.Equipped:Connect(function()

    if MotorCheck.Value == true then
        -- don't run this portion of the code --
    else
        if Tool:FindFirstChild("Handle") and Tool.RequiresHandle == false then
            warn("["..script.Name.."]: RequiresHandle is turned off, but there is a part named 'Handle' currently inside the Tool. Please make sure to re-name the part to something else as well as specifying the Tools main part to attach to on this script to prevent further issues.")
        else
            Motor6D.Part0 = script.Parent.Parent:WaitForChild(BodyPartName) -- Change the name of this to the BodyPart you'd like to use, or configure it in Properties on this Script --
            Motor6D.Part1 = Tool:WaitForChild(ToolPartName) -- switch this to a specific body part if you feel like using more than 1 Handle part.
        end
    end

--[[
My previous write of this code was wrong. I didn't need to make a MotorCheck value to see if the Tool was equipped previously.
There was just a tiny issue that caused me to have to incorporate this. For old times sake, the first one won't run if MotorCheck is true.
Hopefully this solves some replication bugs.
]]

    if MotorCheck.Value == true then
        if Tool:FindFirstChild("Handle") and Tool.RequiresHandle == false then
            warn("["..script.Name.."]: RequiresHandle is turned off, but there is a part named 'Handle' currently inside the Tool. Please make sure to re-name the part to something else as well as specifying the Tools main part to attach to on this script to prevent further issues.")
        else
            Motor6D.Part0 = script.Parent.Parent:WaitForChild(BodyPartName)
            Motor6D.Part1 = Tool:WaitForChild(ToolPartName)  -- switch this to a specific body part if you feel like using more than 1 Handle part.
        end
    end

--[[
Unfortunately, Roblox has no built-in way to stop the Handle from spawning a
RightGrip for the Right Arm (or RightHand). The code below will check a few things like
RequiresHandle, and will rightfully remove any RightGrip if present.
]]

    if Tool.RequiresHandle == false then

        if Tool:FindFirstChild("Handle") then
            -- do not attempt to fetch the RightArmGrip because the Developer is not using a Handle specifically. --
            warn("["..script.Name.."]: RequiresHandle is false on "..Tool.Name.." but there is a BasePart named 'Handle' inside the Tool. This might cause unexpected results. Only use 'RequiresHandle = false' if you're not using a Handle.")

            MotorCheck.Value = true
        else
            RightArmGrip = script.Parent.Parent[BodyPartName]:WaitForChild("RightGrip")
            task.wait()
            RightArmGrip:Destroy()

            MotorCheck.Value = true
        end

    elseif Tool.RequiresHandle == true then
        RightArmGrip = script.Parent.Parent[BodyPartName]:WaitForChild("RightGrip")
        task.wait()
        RightArmGrip:Destroy()

        MotorCheck.Value = true
    end 
end)

--[[
This part of the script will detach the Motor6D(s) from the Tools handle upon
being unequipped. This prevents any issues when we try to equip a second time.
]]

script.Parent.ChildRemoved:Connect(function()
    Motor6D.Part1 = nil
    Motor6D.Part0 = nil
end)

Tool.Unequipped:Connect(function()
    Motor6D.Part1 = nil
    Motor6D.Part0 = nil
end)

-- Need help or assistance? Please go to (https://devforum.roblox.com/t/how-to-animate-tool-handles-easily-specifically-melees-unsure-of-guns)

finally, some extra images if it provides any insights

edit: my image links were cut off for some odd reason

image1

image2

I would have asked Nilociety myself, but roblox forums doesn't seem to let me DM or comment on posts until I have an insane amount of read time

1 answer

Log in to vote
0
Answered by 1 year ago

This tutorial works! Just had to iron out some handle position bugs from my previous animations and now they work like a charm

https://devforum.roblox.com/t/how-to-animate-tools-the-easiest-and-best-way-for-melees/1654589

https://streamable.com/sfwn5e

0
I think I might only be able to accept this as an answer if I comment, so I will brandons2005 87 — 1y
0
still can't, oh well I'll just mark the above answer as accepted brandons2005 87 — 1y
0
oof i just realized my answer was wrongn so embarrassing for me T3_MasterGamer 2189 — 1y
0
i just removed my answer but dw i will ask someone to lock ur answer so that no one will try to answer it even tho u already solved it T3_MasterGamer 2189 — 1y
Ad

Answer this question