So basically its supposed to spawn a block 30 studs above the player in a random spot thats emitting a light down so its a offscreen lightning effect heres the script and the lightning service im honestly not sure id have it work so im hoping for a push in the right direction.
local Storm = require(script.Storm)
Storm:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Storm:SetDirection(script.Direction.Value)
Storm:SetTransparency(script.Transparency.Value)
Storm:SetSpeedRatio(script.SpeedRatio.Value)
Storm:SetIntensityRatio(script.IntensityRatio.Value)
Storm:SetLightInfluence(script.LightInfluence.Value)
Storm:SetLightEmission(script.LightEmission.Value)
Storm:SetVolume(script.Volume.Value)
Storm:SetSoundId(script.SoundId.Value)
Storm:SetStraightTexture(script.StraightTexture.Value)
Storm:SetTopDownTexture(script.TopDownTexture.Value)
Storm:SetSplashTexture(script.SplashTexture.Value)
local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold and p.CanCollide
end
)
elseif script.TransparencyConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold
end
)
elseif script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.CanCollide
end
)
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local stormEvent = ReplicatedStorage:WaitForChild("StormEvent")
local stormEnabled = false
-- Create the Lightning Block with SpotLight if it doesn't exist
local function createLightningBlock()
local lightningBlock = game.Workspace:FindFirstChild("LightningBlock")
if not lightningBlock then
lightningBlock = Instance.new("Part")
lightningBlock.Name = "LightningBlock"
lightningBlock.Size = Vector3.new(2, 2, 2)
lightningBlock.Anchored = true
lightningBlock.CanCollide = false
lightningBlock.Transparency = 1
lightningBlock.Parent = game.Workspace
local lightningSpotlight = Instance.new("SpotLight")
lightningSpotlight.Name = "Lightning"
lightningSpotlight.Color = Color3.fromRGB(0, 0, 255)
lightningSpotlight.Brightness = 10
lightningSpotlight.Range = 60
lightningSpotlight.Angle = 45
lightningSpotlight.Face = Enum.NormalId.Bottom
lightningSpotlight.Enabled = false
lightningSpotlight.Parent = lightningBlock
end
return lightningBlock
end
-- Function to create the lightning flash effect
local function createLightningFlash(player)
print("Creating lightning flash for player:", player.Name)
-- Define the radius around the player where the flash will spawn
local radius = 40
-- Calculate a random position around the player, 30 studs above them
local playerPosition = player.Character and player.Character.PrimaryPart.Position or Vector3.new(0, 0, 0)
local randomOffset = Vector3.new(
math.random(-radius, radius),
30, -- 30 studs above the player
math.random(-radius, radius)
)
local flashPosition = playerPosition + randomOffset
-- Get or create the Lightning Block with SpotLight
local lightningBlock = createLightningBlock()
lightningBlock.CFrame = CFrame.new(flashPosition, playerPosition) -- Ensure the part faces the player
print("LightningBlock moved to position:", flashPosition)
-- Enable the SpotLight
local lightningSpotlight = lightningBlock:FindFirstChild("Lightning")
if lightningSpotlight then
lightningSpotlight.Enabled = true
else
print("No SpotLight found in LightningBlock")
end
-- Print the message indicating lightning has spawned for the player
print("Spawned lightning for player:", player.Name)
-- Wait for 1 second
wait(1)
-- Disable the SpotLight
if lightningSpotlight then
lightningSpotlight.Enabled = false
end
print("LightningBlock visibility set to false")
end
local function fadeStorm(action, duration)
local startTime = tick()
local initialIntensity = action == "start" and 0 or 1
local targetIntensity = action == "start" and 1 or 0
while tick() - startTime < duration do
local elapsed = tick() - startTime
local progress = elapsed / duration
Storm:SetIntensityRatio(initialIntensity + (targetIntensity - initialIntensity) * progress)
wait(0.03)
end
Storm:SetIntensityRatio(targetIntensity)
end
stormEvent.OnClientEvent:Connect(function(action)
if action == "EnableStorm" then
Storm:Enable()
fadeStorm("start", 10) -- Fade in the storm over 10 seconds
stormEnabled = true
-- Start lightning flashes
spawn(function()
while stormEnabled do
wait(math.random(30, 60)) -- Wait for a random time between 30 seconds to 1 minute
for _, player in pairs(Players:GetPlayers()) do
createLightningFlash(player)
end
end
end)
elseif action == "DisableStorm" then
fadeStorm("stop", 10) -- Fade out the storm over 10 seconds
wait(10) -- Wait for fade out to complete before disabling
Storm:Disable()
stormEnabled = false
end
end)
ps the entire script is locally based so only the player should see the lightning
i looked a little deeper and i honestly still cant find a way around it but this is the more updated code ig?
local Storm = require(script.Storm)
Storm:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Storm:SetDirection(script.Direction.Value)
Storm:SetTransparency(script.Transparency.Value)
Storm:SetSpeedRatio(script.SpeedRatio.Value)
Storm:SetIntensityRatio(script.IntensityRatio.Value)
Storm:SetLightInfluence(script.LightInfluence.Value)
Storm:SetLightEmission(script.LightEmission.Value)
Storm:SetVolume(script.Volume.Value)
Storm:SetSoundId(script.SoundId.Value)
Storm:SetStraightTexture(script.StraightTexture.Value)
Storm:SetTopDownTexture(script.TopDownTexture.Value)
Storm:SetSplashTexture(script.SplashTexture.Value)
local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold and p.CanCollide
end
)
elseif script.TransparencyConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold
end
)
elseif script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.CanCollide
end
)
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local stormEvent = ReplicatedStorage:WaitForChild("StormEvent")
local stormEnabled = false
-- Create the Lightning Block with SpotLight if it doesn't exist
local function createLightningBlock()
local lightningBlock = game.Workspace:FindFirstChild("LightningBlock")
if not lightningBlock then
lightningBlock = Instance.new("Part")
lightningBlock.Name = "LightningBlock"
lightningBlock.Size = Vector3.new(2, 2, 2)
lightningBlock.Anchored = true
lightningBlock.CanCollide = false
lightningBlock.Transparency = 1
lightningBlock.Parent = game.Workspace
local lightningSpotlight = Instance.new("SpotLight")
lightningSpotlight.Name = "Lightning"
lightningSpotlight.Color = Color3.fromRGB(0, 0, 255)
lightningSpotlight.Brightness = 10
lightningSpotlight.Range = 60
lightningSpotlight.Angle = 45
lightningSpotlight.Face = Enum.NormalId.Bottom
lightningSpotlight.Enabled = false
lightningSpotlight.Parent = lightningBlock
end
return lightningBlock
end
-- Function to create the lightning flash effect
local function createLightningFlash(player)
-- Define the radius around the player where the flash will spawn
local radius = 40
-- Calculate a random position around the player, 30 studs above them
local playerPosition = player.Character and player.Character.PrimaryPart.Position or Vector3.new(0, 0, 0)
local randomOffset = Vector3.new(
math.random(-radius, radius),
30, -- 30 studs above the player
math.random(-radius, radius)
)
local flashPosition = playerPosition + randomOffset
-- Get or create the Lightning Block with SpotLight
local lightningBlock = createLightningBlock()
lightningBlock.CFrame = CFrame.new(flashPosition, playerPosition) -- Ensure the part faces the player
-- Enable the SpotLight
local lightningSpotlight = lightningBlock:FindFirstChild("Lightning")
if lightningSpotlight then
lightningSpotlight.Enabled = true
end
-- Print the message indicating lightning has spawned for the player
print("Spawned lightning for player:", player.Name)
-- Wait for 1 second
wait(1)
-- Disable the SpotLight
if lightningSpotlight then
lightningSpotlight.Enabled = false
end
end
local function fadeStorm(action, duration)
local startTime = tick()
local initialIntensity = action == "start" and 0 or 1
local targetIntensity = action == "start" and 1 or 0
while tick() - startTime < duration do
local elapsed = tick() - startTime
local progress = elapsed / duration
Storm:SetIntensityRatio(initialIntensity + (targetIntensity - initialIntensity) * progress)
wait(0.03)
end
Storm:SetIntensityRatio(targetIntensity)
end
stormEvent.OnClientEvent:Connect(function(action)
if action == "EnableStorm" then
Storm:Enable()
fadeStorm("start", 10) -- Fade in the storm over 10 seconds
stormEnabled = true
-- Start lightning flashes
spawn(function()
while stormEnabled do
wait(math.random(30, 60)) -- Wait for a random time between 30 seconds to 1 minute
for _, player in pairs(Players:GetPlayers()) do
createLightningFlash(player)
end
end
end)
elseif action == "DisableStorm" then
fadeStorm("stop", 10) -- Fade out the storm over 10 seconds
wait(10) -- Wait for fade out to complete before disabling
Storm:Disable()
stormEnabled = false
end
end)
alright i figured it out but if anyone else wants the script its kind of situational but if you ever need help here
local Storm = require(script.Storm)
Storm:SetColor(Color3.fromRGB(script.Color.Value.x, script.Color.Value.y, script.Color.Value.z))
Storm:SetDirection(script.Direction.Value)
Storm:SetTransparency(script.Transparency.Value)
Storm:SetSpeedRatio(script.SpeedRatio.Value)
Storm:SetIntensityRatio(script.IntensityRatio.Value)
Storm:SetLightInfluence(script.LightInfluence.Value)
Storm:SetLightEmission(script.LightEmission.Value)
Storm:SetVolume(script.Volume.Value)
Storm:SetSoundId(script.SoundId.Value)
Storm:SetStraightTexture(script.StraightTexture.Value)
Storm:SetTopDownTexture(script.TopDownTexture.Value)
Storm:SetSplashTexture(script.SplashTexture.Value)
local threshold = script.TransparencyThreshold.Value
if script.TransparencyConstraint.Value and script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold and p.CanCollide
end
)
elseif script.TransparencyConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.Transparency <= threshold
end
)
elseif script.CanCollideConstraint.Value then
Storm:SetCollisionMode(
Storm.CollisionMode.Function,
function(p)
return p.CanCollide
end
)
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local stormEvent = ReplicatedStorage:WaitForChild("StormEvent")
local stormEnabled = false
-- Function to create the lightning flash effect using the premade LightningBlock
local function createLightningFlash(player)
-- Define the radius around the player where the flash will spawn
local radius = 40
-- Calculate a random position around the player, 30 studs above them
local playerPosition = player.Character and player.Character.PrimaryPart.Position or Vector3.new(0, 0, 0)
local randomOffset = Vector3.new(
math.random(-radius, radius),
30, -- 30 studs above the player
math.random(-radius, radius)
)
local flashPosition = playerPosition + randomOffset
-- Get the premade LightningBlock from Lighting
local lightningBlock = Lighting:FindFirstChild("LightningBlock")
if lightningBlock then
local clonedLightningBlock = lightningBlock:Clone()
clonedLightningBlock.CFrame = CFrame.new(flashPosition, playerPosition) -- Ensure the part faces the player
clonedLightningBlock.Parent = game.Workspace
-- Enable the SpotLight
local lightningSpotlight = clonedLightningBlock:FindFirstChild("Lightning")
if lightningSpotlight then
lightningSpotlight.Enabled = true
print("Spawned lightning for player:", player.Name)
-- Wait for 1 second
wait(1)
-- Disable the SpotLight
lightningSpotlight.Enabled = false
end
-- Remove the cloned block after the flash
clonedLightningBlock:Destroy()
else
warn("LightningBlock not found in Lighting service")
end
end
local function fadeStorm(action, duration)
local startTime = tick()
local initialIntensity = action == "start" and 0 or 1
local targetIntensity = action == "start" and 1 or 0
while tick() - startTime < duration do
local elapsed = tick() - startTime
local progress = elapsed / duration
Storm:SetIntensityRatio(initialIntensity + (targetIntensity - initialIntensity) * progress)
wait(0.03)
end
Storm:SetIntensityRatio(targetIntensity)
end
stormEvent.OnClientEvent:Connect(function(action)
if action == "EnableStorm" then
Storm:Enable()
fadeStorm("start", 10) -- Fade in the storm over 10 seconds
stormEnabled = true
-- Start lightning flashes every 5 seconds for testing
spawn(function()
while stormEnabled do
wait(5) -- Wait for 5 seconds
for _, player in pairs(Players:GetPlayers()) do
createLightningFlash(player)
end
end
end)
elseif action == "DisableStorm" then
fadeStorm("stop", 10) -- Fade out the storm over 10 seconds
wait(10) -- Wait for fade out to complete before disabling
Storm:Disable()
stormEnabled = false
end
end)
-- Listen for chat commands to manually trigger lightning
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == ";l" then
createLightningFlash(player)
end
end)
end)