Weld rotation doesn't stay?

Hello there!

I’m pretty new at doing welds/cframes or just scripting tools in general, just so you know. I’m trying to achieve a 180-degree rotation on my tool when I use it.

  • The issue is that it works fine, but it doesn’t stay rotated for some reason. It happens when the tool is unequipped and equipped. I don’t know what to do to solve the issue.

  • The video below will show you what I mean with it doesn’t stay rotated after unequipping and equipping:

Script below:

local function doWeld()
	local Character = script.Parent.Parent.Parent
		local Handle = script.Parent.Parent.Holders
			local Weld = Instance.new("Weld",Handle)
			Weld.Part0 = Handle
			Weld.Part1 = Character["Head"]
		Weld.C0 = CFrame.new(0,-0.4,0)
	Weld.C0 = Handle.Weld.C0 * CFrame.Angles(0, math.rad(180), 0) --> Rotation part problem here.
end
1 Like

My memory with tools is sketchy, but I’m pretty sure the weld is breaking when its unequipped, so make sure its created each time its equipped. If thats not the issue then post more code

Although, I also recommend just plain not using tools, they’re quite limiting and a fairly old feature.

And finally, there is no reason to tab your code like that lol, it’ll get confusing. If you want to space it out use spare lines i.e

local function doWeld()
	local Character = script.Parent.Parent.Parent
    local Handle = script.Parent.Parent.Holders
	
    local Weld = Instance.new("Weld",Handle)
	Weld.Part0 = Handle
	Weld.Part1 = Character["Head"]

	Weld.C0 = CFrame.new(0,-0.4,0)
	Weld.C0 = Handle.Weld.C0 * CFrame.Angles(0, math.rad(180), 0) --> Rotation part problem here.
end
1 Like

I don’t know if any code was changed between the OP and the solution, but after looking over this code for several answers, I thought of something; isn’t part of the problem the fact that you set the parent first before the properties?

Don’t do that.

When you attach the weld to the DataModel first before setting the parent, your part is joined and physically simulated according to that. You will see significant change by parenting after setting your properties.

2 Likes