Lightning bolts hop and after a while launch away for some reason

I’m working on my lightning module, and I’m working on the actual lightning. The problem is my module isn’t working, no errors.
Here’s everything I know:

  • What isn’t working? The bolt’s CFrame isn’t being properly set. [UNSOLVED, the bolts are just facing straight)

  • What is happening? The bolts created are somewhat hopping [SOLVED]

  • How am I doing this right now? Every time I create a bolt, I insert a script that sets its CFrame to look at the point right in front of it.

  • What have I tried doing? Unfortunately, I don’t have much understanding of CFrames, so I haven’t done anything yet.

Here’s a video of me on my alt showing what happens (The blue neon things are the bolts)

EDIT: On my end, the video is glitched and is broken only on the DevForum. If it is also glitched on your device and most of the video is unable to be seen, let me know in the replies so I can send the wmv version of the file.

Code

Snippet of code in the module responsible for creating the bolts:

local function lightningBoltCreate(pointFolder : Instance)
	local boltFolder = Instance.new("Folder")
	boltFolder.Name = "BoltFolder" .. assignName
	for index, child in pairs(pointFolder:GetChildren()) do
		if index == 1 then continue end
		local a1stPoint = ((pointFolder:GetChildren())[index-1])
		local bolt = Instance.new("Part")
		bolt.Color = Color3.fromRGB(0, 255, 255)
		bolt.Material = Enum.Material.Neon
		bolt.Size = Vector3.new(1, 1, (a1stPoint.Position - child.Position).Magnitude)
		bolt.CFrame = a1stPoint.CFrame:Lerp(child.CFrame, 0.5)
		bolt.CFrame = CFrame.lookAt(bolt.Position, child.Position)
		bolt.Name = "Bolt " .. a1stPoint.Name .. " " .. child.Name
		bolt.Parent = game.Workspace
		local boltLight = Instance.new("PointLight")
		boltLight.Color = bolt.Color
		boltLight.Parent = bolt
		local scriptClone = boltScript:Clone()
		scriptClone.Parent = bolt
		scriptClone.Disabled = false
	end
end

Code being parented to the bolt:

local name = script.Parent.Name
local str = string
local split = str.split(name, " ")
local toLookAt = split[3]
local runService = game:GetService("RunService")
runService.Heartbeat:Connect(function()
	script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, game:FindFirstChild(toLookAt, true).Position)
end)

It is more ethical to simply upload the video as in unlisted link to YouTube and send the link here, because not everyone can see wmv files. But yes, the video you sent is glitched.


While I’m only basing this guess off an assumption of what’s going on, did you try anchoring your lighting bolt?

Yeah, that fixed it, but why are all the lightning bolts just straight on a line?

Here’s the output and explorer:

And here’s the current bolt script:

local name = script.Parent.Name
local str = string --Excuse me for being a bit lazy XD
local split = str.split(name, " ")
local toLookAt = split[3]
local runService = game:GetService("RunService")
local currentAssignedName = str.split(script.Parent.Parent.Name, " ")
runService.Heartbeat:Connect(function()
	script.Parent.CFrame = CFrame.lookAt(script.Parent.Position, script.Parent.Parent.Parent:WaitForChild("LightingPoints " .. currentAssignedName[2]):WaitForChild(toLookAt).Position)
end)

Either way, you solved the problem, at least they don’t hop and launch anymore