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

Tool parts get farther and farther every time you equip tool while moving?

http://www.roblox.com/Tool-testing-place?id=179683718

When you equip the tool and Unequip while moving it like stays back.

is there any way to make it move back to the player every time you equip it?

Thanks,

Exsius ;)

I tried to use a CFrame code to bring in back to the player but it wont work

Tool = script.Parent
--WepFix = Tool.Gun  Ignore
Head = script.Parent.Parent.Parent.Character.Head
       



Tool.Equipped:connect(function(mouse)
	
	
	 script.Parent.Gun.C0 = CFrame.new()
	script.Parent.Gun.C1 = CFrame.new(0, 1, 0) * CFrame.Angles(0,0, 0)      --Cframe
	
	script.Parent.Gun.Anchored = false
	
weld = Instance.new("Weld")
weld.Part0 = Head
weld.C0 = Head.CFrame:inverse()
weld.Part1 = script.Parent.Gun
weld.C1 = script.Parent.Gun.CFrame:inverse()
weld.Parent = script.Parent
wait(1)

	

		
	
	
end)



1 answer

Try this out:

local Tool=script.Parent
local Player=game.Players:FindFirstChild(Tool.Parent.Name) or Tool.Parent.Parent
local Head=Player.Character.Head
local Gun=script.Parent.Gun

function Weld()
	local W=Gun:FindFirstChild("GunWeld") if W then W:destroy() end
	Gun.Anchored=true
	Head.Anchored=true
	local Weld=Instance.new("Weld",Gun)
	Weld.Name="GunWeld"
	Weld.Part0=Head
	Weld.Part1=Gun
	Weld.C0=Head.CFrame:inverse()
	Weld.C1=Gun.CFrame:inverse()
	Gun.Anchored=false
	Head.Anchored=false
end
Tool.Equipped:connect(Weld)

2 comments

0

Please do not just post code, for that does not help the user to learn, please provide explanation behind answer, or else it does not help the user to expand his/her knowledge.

0

...An idiot could tell the only thing I did was anchor and then unanchor the parts

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