varenst
(varenst_gaming)
November 23, 2021, 3:48pm
#1
Help with Motor6D script
I wanted to make gun stick to uppertorso but it dose not seem to work
My script `
local tool = script.Parent
local player = tool.Parent.Parent
local character = player.Character
tool.Equipped:Connect(function(Animpro)
character.UpperTorso:WaitForChild("RightGrip"):Destroy()
local Motor6D = Instance.new("Motor6D",character.UpperTorso)
Motor6D.Name = "Engineers_RevolverMotor6D"
Motor6D.Part0 = character.UpperTorso
Motor6D.Part1 = tool.Handle
Motor6D.C0 = CFrame.new(-0.1,-0.2,0.3)
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://8078765593"
Animpro = character.Humanoid:LoadAnimation(Anim)
Animpro:Play()
end)` But sadly it dose not work gun sticks to righthand and animation is not playing correct
Sorry for my English
Scottifly
(Scottifly)
November 23, 2021, 8:22pm
#2
You set the C0 using
Motor6D.C0 = CFrame.new(-0.1,-0.2,0.3)
but I can’t see anywhere that you set the Motor6D.C1
.
Forummer
(Forummer)
November 24, 2021, 12:59am
#3
You forgot to assign the C1 property of the Motor6D instance.
local character = player.Character
local Anim = Instance.new("Animation")
Anim.AnimationId = "rbxassetid://8078765593"
Animpro = character.Humanoid:LoadAnimation(Anim)
tool.Equipped:Connect(function(Animpro)
character.UpperTorso:WaitForChild("RightGrip"):Destroy()
local Motor6D = Instance.new("Motor6D")
Motor6D.Parent = character.UpperTorso
Motor6D.Name = "Engineers_RevolverMotor6D"
Motor6D.Part0 = character.UpperTorso
Motor6D.Part1 = tool.Handle
Motor6D.C0 = CFrame.new(-0.1,-0.2,0.3)
Motor6D.C1 = CFrame.new(0, 0, 0)
Animpro:Play()
end)
Also avoid reloading the same animation (resulting in the repetitive creation of the same AnimationTrack instance) by moving the code which loads the animation outside of the function connected to the tool’s Equipped event, also you should avoid using the parent parameter of “Instance.new()” as it’s highly inefficient.
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out.
Tthere are several ways to create a ROBLOX object in Lua:
local obj = Instance.new(‘type’); fill obj fields
local obj = Instance.new(‘type’, parent); fill obj fields
local obj = util.Create(‘type’, { field1 = value1, … })
If you care at all about performance, please only use the first option - I wi…