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

How can i fix this Motor6D script to prevent this weird offset when i equip a tool?

For this sword, I made a script that manually inserts a Motor6D to connect the Right Hand and the tool when the tool is equipped. This is necessary for me to play my animations since i animate the tool itself along with the R15 Rig.

As you can see here, there's a split second where the Motor6D hasn't been attached yet so the tool just seems to be out of place.

See this example

This is my local script

--//Services
local replicatedStorage = game:GetService('ReplicatedStorage')


--//Variables
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local rightHand = char:WaitForChild('RightHand')
local tool = script.Parent.Parent
local grip = script.Parent
local folder = replicatedStorage:WaitForChild('SwordRemotes') 
local connectM6D = folder:WaitForChild('ConnectM6D')
local disconnectM6D = folder:WaitForChild('DisconnectM6D')


tool.Equipped:Connect(function()
	grip.CFrame = rightHand.CFrame 
	connectM6D:FireServer(char,grip)
end)


tool.Unequipped:Connect(function()
	disconnectM6D:FireServer(char,grip)
end)

And this is my server script

local replicatedStorage = game:GetService('ReplicatedStorage')
local folder = replicatedStorage:WaitForChild('SwordRemotes')
local connectM6D = folder:WaitForChild('ConnectM6D')
local disconnectM6D = folder:WaitForChild('DisconnectM6D')


connectM6D.OnServerEvent:Connect(function(player,char,grip)
	local rightHand = char.RightHand
	
	local rightMotor = Instance.new('Motor6D')
	
	rightMotor.Name = 'RightMotor'
	rightMotor.Part0 = rightHand
	rightMotor.Part1 = grip 
	rightMotor.Parent = rightHand  
	
end)


disconnectM6D.OnServerEvent:Connect(function(player,char,grip)
	local rightHand = char.RightHand
	
	local rightMotor = rightHand:FindFirstChild('RightMotor')
	if rightMotor then
		rightMotor:Destroy()
	end
end)

1 answer

You could do something simple like make it invisible for a split second until the sword is in place.

connectM6D.OnServerEvent:Connect(function(player,char,grip)
    local rightHand = char.RightHand

    local rightMotor = Instance.new('Motor6D')
    grip.Visible = false -- (change grip to whatever the tool part is)
    rightMotor.Name = 'RightMotor'
    rightMotor.Part0 = rightHand
    rightMotor.Part1 = grip 
    rightMotor.Parent = rightHand  
    wait(0.1) -- change according to if it makes it look better
    grip.Visible = true
end)

Just an idea. Hope it helps.

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