How to Make Lightning

How do I script Lightning I saw some old posts on it but they never gave a really good script on how to do it, only the logic. I’m not very good at scripting so Idk how to do it. Can someone help?

1 Like

You could use math.random to randomize the position. Then use Raycasting to create the part.


You can view this tutorial, and modify the script as you wish.
I don’t know if that, or something like that.


That won does not give the script :confused: RIP

How would I do that? I’m trying to make it “jump” between 2 parts

Wdym? It should give you the script its a tutorial, do you mean to copy and paste?


Yeah because I’m a slow typer :confused: welp

do you know how to make this script go from one part to another instead of just vertical?

local serv = game.ReplicatedStorage

function CastLightningDown(head) -- vector3 start position

	local maxRange = 5 -- how far in polar coordinates can the lightning go
	local heightOffset = 5 -- how far the 3D vector is offset

	local boltParts = {}

	while head.Y > 0 do -- the advantage of using a Vector3 as the end of the lightning bolt
		local angle = math.pi*4*math.random() -- 4 because I don't trust the random distribution
		local radius = math.random()*maxRange -- radius

		local dir =*radius,-heightOffset,-math.sin(angle)*radius) -- converting the XY plane of a graph into the XZ plane of a part requires Z to be negative

		local newPart = serv.Lightning:Clone()
		newPart.Size =,.1,math.random(1,5)) -- component change to take advantage of CFrame's 2-vector construction method
		newPart.CFrame =,head+dir)*,0,-newPart.Size.Z/2) -- starting point, target point, and offset by half the length
		head = newPart.CFrame*,0,-newPart.Size.Z/2) -- move the head to the end of the part so we can continuously cast bolts
		newPart.Parent = workspace	

while true do
	for i = 1, 5 do -- make 30 lightning bolts
	local children = workspace:GetChildren()
	for i, child in ipairs(children) do
		if child.Name == "Lightning" then


1 Like

change each part of the script, and see what they do

1 Like

I said you could use Raycasting to send an invisible ray to that part, then create a part out of it.

Here’s a developer page for Raycasting if you need it.

1 Like