Any idea why my code won't work?

-- Vars
local bonesTable = script.Parent.Plane:GetChildren()
local ControlPoint = workspace.ControlPoint
-----------------------

-- Remove Exception
 local exceptionIndex = table.find(bonesTable, "Exception")
table.remove(bonesTable, exceptionIndex)
print(bonesTable)
-----------------------

-- Test Laser Properties
local testLaser = Instance.new("Part")
testLaser.CanTouch = false
testLaser.Anchored = true
testLaser.Transparency = 0
testLaser.Color = Color3.new(1, 0.423529, 0.137255)


--

for key, bone in bonesTable do
	local boneDistanceFromPoint = (ControlPoint.Position - bone.Position).Magnitude
	local newLaser = testLaser:Clone()
	newLaser.Parent = workspace
	
	print(bone.Name .. " is " .. boneDistanceFromPoint .. " studs away from ControlPoint.")
	
	local startcf = CFrame.new(bone.Position, ControlPoint.Position) -- Finding the CFrame between the two parts
	local cf = startcf:ToWorldSpace(CFrame.new(0,0,-boneDistanceFromPoint/2))
	newLaser.CFrame = cf
	newLaser.Size = Vector3.new(2,2,boneDistanceFromPoint)
end

How the bones look:

The result:

What I expected:

Any idea? Please explain in detail as I am looking to learn, not to copy paste.

1 Like

you need to use bone.WorldPosition instead of bone.Position

to get the position between the 2 points it should be

 local center = (ControlPoint.Position + bone.WorldPosition) / 2

and not

local startcf = CFrame.new(bone.Position, ControlPoint.Position) -- Finding the CFrame between the two parts
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.