Randomized rotation that target a certain part

  1. What do you want to achieve?
  • So i make a lighting bold module that uses Random.new() to make the rotation. But i want make the rotation targetting a certain part

  • Here Is My Module Script

local module = {}

function module.Make(Size:Vector3,Attachment:Attachment,MaxRot:number,FadeTime:number)
	local light = {}
	local ins = Instance.new('Part')
	ins.Parent = workspace.ex
	ins.Size = Size
	ins.Material = Enum.Material.Neon
	ins.Color = Color3.fromRGB(255,255,0)
	ins.CFrame = Attachment.WorldCFrame
	table.insert(light,ins)
	
	local lastchild = nil
	for i=1,20 do
		if i == 1 then
			local child = Instance.new('Part')
			child.Parent = workspace.ex
			child.Size = Size
			child.Material = Enum.Material.Neon
			child.Color = Color3.fromRGB(255,255,0)
			table.insert(light,child)
			
			local newpivot = CFrame.new((ins.CFrame:ToWorldSpace(CFrame.new(ins.Size.X/2,0,0))).Position) 
			local offset = newpivot:toObjectSpace(child.CFrame) 
			newpivot = newpivot * CFrame.Angles(0, math.rad(Random.new():NextInteger(-MaxRot,MaxRot)), 0) 
			child.CFrame = newpivot * offset * ins.CFrame:ToWorldSpace(CFrame.new(ins.Size.X,0,0))
			lastchild = child
		else
			local child = Instance.new('Part')
			child.Parent = workspace.ex
			child.Size = Size
			child.Material = Enum.Material.Neon
			child.Color = Color3.fromRGB(255,255,0)
			table.insert(light,child)
			
			local newpivot = CFrame.new((lastchild.CFrame:ToWorldSpace(CFrame.new(lastchild.Size.X/2,0,0)).Position)) 
			local offset = newpivot:toObjectSpace(child.CFrame) 
			newpivot = newpivot * CFrame.Angles(0, math.rad(Random.new():NextInteger(-MaxRot,MaxRot)), 0) 
			child.CFrame = newpivot * offset * lastchild.CFrame:ToWorldSpace(CFrame.new(lastchild.Size.X,0,0))
			lastchild = child
		end
	end
	task.wait(FadeTime)
	for _n, destroy in ipairs(light) do
		spawn(function()
			local t = game:GetService('TweenService'):Create(destroy,TweenInfo.new(.3,Enum.EasingStyle.Linear),{Transparency = 1})
			t:Play() t.Completed:Wait()
			destroy:Destroy()
		end)
		task.wait()
	end
end

return module

What i mean targetting/aiming is like this:

External Media

if youre having issue with playing the video:
robloxapp-20230520-1943539.wmv (357.0 KB)

I want the part that makes the lightning is targetting the next part shown on the video. thanks

1 Like

Why reinvent the wheel when there are many libraries out there for this? Some popular examples include Lighting Beams and ElectricArc. Also if you want to make a simple lighting effect you can figure out how the semi-randomized angles of each lighting part should act from this post.

1 Like

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