Also, you were right about the addition. I’m completely rusty on ROBLOX CFrames.
This is what happens when you indulge into many different engines.
Also, you were right about the addition. I’m completely rusty on ROBLOX CFrames.
This is what happens when you indulge into many different engines.
It’s just this:
local runService = game:GetService("RunService")
local point = script.Parent
local cframeAmount = point.CFrame
local random = Random.new()
runService.Heartbeat:Connect(function()
local Outoffsetno = random:NextNumber(0, 2)
local chooseOperation = math.random(1, 2)
if chooseOperation == 1 then
point.CFrame += cframeAmount.UpVector * Outoffsetno
else
point.CFrame -= cframeAmount.UpVector * Outoffsetno
end
task.wait(random:NextNumber(1, 2))
end)
This code is meant to be in a disabled script, which is cloned and parented to a point and enabled.
I also need the code that creates the points themselves.
Alright, it’s just a module which I’m requiring to create the points, but anyways:
local lightningmodule = {}
local random = Random.new()
local defaultColor = Color3.fromRGB(0, 127, 255)
local movePointScript = script:WaitForChild("MoveScript")
local function lightningPointCreate(amountOfPoints : number, cframeAmount : CFrame, color : Color3, isStraight : bool, parent : Instance, start1 : Instance)
if color == nil then
color = defaultColor
if isStraight == nil then
isStraight = true
end
end
for i = 1, math.floor(amountOfPoints) do
local point = Instance.new("Part")
point.Size = Vector3.new(1, 1, 1)
point.Anchored = true
point.CFrame = cframeAmount
point.Color = color
point.Transparency = 0.75
point.CanCollide = false
point.Parent = parent
if isStraight == false then
local scrip = movePointScript:Clone()
scrip.Disabled = false
scrip.Parent = point
end
end
end
function lightningmodule.Create(point1 : Instance, point2 : Instance, color, isStraightLine)
point2.Orientation = point1.Orientation
local timesToGetLightningStrike = math.random(5, 6)
local tableOfLerps = {}
for i = 1, timesToGetLightningStrike do
local lerpAlpha = random:NextNumber(0.1/timesToGetLightningStrike, 0.1)
local lerpCFrame = point1.CFrame:Lerp(point2.CFrame, lerpAlpha)
if #tableOfLerps ~= 0 then
local lastNumTable = tableOfLerps[#tableOfLerps]
local lastnum = lastNumTable[2]
lerpAlpha = lastnum + random:NextNumber(0.15, 0.2)
print(lerpAlpha, lerpAlpha < 1 and lerpAlpha > 0)
if lerpAlpha >= 1 or lerpAlpha <= 0 then
repeat
print(lerpAlpha, lerpAlpha < 1 and lerpAlpha > 0)
task.wait()
until lerpAlpha < 1 and lerpAlpha > 0
end
lerpCFrame = point1.CFrame:Lerp(point2.CFrame, lerpAlpha)
local lastTable = {lerpCFrame, lerpAlpha}
table.insert(tableOfLerps, lastTable)
else
local lastTable = {lerpCFrame, lerpAlpha}
table.insert(tableOfLerps, lastTable)
end
end
local folderOfPoints = Instance.new("Folder")
folderOfPoints.Parent = game.Workspace
folderOfPoints.Name = "LightningPoints"
for i, v in ipairs(tableOfLerps) do
lightningPointCreate(1, v[1], color, isStraightLine, folderOfPoints, point1)
end
end
return lightningmodule
Try this
local DEFAULT_COLOR = Color3.fromRGB(0, 127, 255)
local LightningModule = {}
local function createLightningPoint(pointCount, cf, color, isStraightLine, parent)
color = color or DEFAULT_COLOR
for i = 1, math.max(1,math.floor(pointCount)) do
local point = Instance.new("Part")
point.Size = Vector3.new(1, 1, 1)
point.Anchored = true
point.CFrame = cf
point.Color = color
point.Transparency = 0.75
point.CanCollide = false
point.Parent = parent
-- add if straight script?
end
end
function LightningModule.Create(point1, point2, color, isStraightLine)
local strikeCount = math.random(5, 6)
local pos1, pos2 = point1.Position, point2.Position
local offset = pos2 - pos1
local defaultStrikeOffset = offset/strikeCount
local maxStrikeDifferential = defaultStrikeOffset/5
local pointsFolder = Instance.new("Folder")
pointsFolder.Name = "LightningPoints"
pointsFolder.Parent = workspace
for i = 1, strikeCount do
local pos = pos1 + defaultStrikeOffset*i + maxStrikeDifferential*(1 - 2*math.random())
createLightningPoint(1, CFrame.new(pos), color, isStraightLine, pointsFolder)
end
-- LINE TRACER, FOR VISUAL EFFECT ONLY, DELETE THIS IN PRODUCTION
local trace = Instance.new("Part", workspace)
trace.Anchored = true
trace.Size = Vector3.new(0.05,0.05,offset.Magnitude)
trace.CFrame = CFrame.new(pos1, pos2) * CFrame.new(0,0,-offset.Magnitude/2)
trace.Color = Color3.new(1,0,0)
end
return LightningModule
you might need to make some slight edits to this but it will give you the effect you are looking for. If you need an explanation on anything, let me know. I added an additional thing at line 39 to visualize the line between the 2 points. You can remove that if you like.
I don’t need help with the module itself, I just need help with the ifStraight script (Which was the script that handles the offset move thing, and the reason why I made this post)
I’ll take a look at this tomorrow, for now I’m going to head off to sleep.
Alright, in the meantime I’ll do something else
I found the solution to this problem, I just had to reset it every time it changed so it would look nicer. Your post is marked as a solution though as it helped greatly, I just modified it a bit to my liking. Thanks