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)