Function doesnt change parts cframe (even tho it did before)

so i made an easy function that should find a cut in a branch and if it finds one, change its size(that works) and change its cframe, which used to work but after some changes it doesnt. (no errors)

> local function znajdzSciecieIPowiekszW(segment)
> 			for i,v in pairs(segment:GetChildren()) do
> 				if v.Name == "Sciecie" then
> 					v.Size = v.Size + Vector3.new(moduledrzewa.wzrostsadzonki.grubosc,0,0)
> 					v.CFrame = v.CFrame * CFrame.new(Vector3.new(0,0,moduledrzewa.wzrostsadzonki.grubosc/2))
> 				end
> 			end
> 		end

sciecie = the cut part, segment = branch, moduledrzewa is the tree module where all tree info is stored, colo, material, max branch size etc.

Did you try printing the cframe before and after modifying it? No change at all, even to the quaternion positions?

didnt think about that for some reason. let me print it

i think i could have found the issue. could be a weld
image

yep. it was a weld, i have fixed it by doing this:

local function znajdzSciecieIPowiekszW(segment)
			for i,v in pairs(segment:GetChildren()) do
				if v.Name == "Sciecie" then
					if v:FindFirstChild("WeldConstraint") then
						local part0 = v.WeldConstraint.Part0
						local part1 = v.WeldConstraint.Part1
						v.WeldConstraint:Destroy()
						v.Size = v.Size + Vector3.new(moduledrzewa.wzrostsadzonki.grubosc,0,0)
						v.CFrame = v.CFrame * CFrame.new(Vector3.new(0,0,moduledrzewa.wzrostsadzonki.grubosc/2))
						local newWeld = Instance.new("WeldConstraint",v)
						newWeld.Part0 = part0
						newWeld.Part1 = part1
					end
				end
			end
		end

basically deletes the weld, changes position and adds the weld again
image

1 Like