I’m having problems with one of the aspects of my game.
Basically, this ball, over here, doesn’t work so well.
When you enter the area of said ‘‘ball’’, the sky should turn dark and lightning effects will sometimes appear. (As shown in the following video.)
Here’s the script that causes the sky to go dark.
local players = game:GetService('Players')
local maxDistance = 241
local L = true
while task.wait(0.1) do
for i, player in players:GetPlayers() do
if player.Character then
if player:DistanceFromCharacter(script.Parent.Position) < maxDistance then
if L == true then
L = false
game.Lighting.Atmosphere.Density = 0.3
game.Lighting.Atmosphere.Color = Color3.new(0.396078, 0.568627, 0.74902)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.4, 0.74902)
game.Lighting.Atmosphere.Haze = 0.1
script["Rain Sound Effect"].Volume = 0.1
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.5
game.Lighting.Atmosphere.Color = Color3.new(0.262745, 0.376471, 0.498039)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.266667, 0.498039)
game.Lighting.Atmosphere.Haze = 1
script["Rain Sound Effect"].Volume = 0.2
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.7
game.Lighting.Atmosphere.Color = Color3.new(0.129412, 0.188235, 0.247059)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.133333, 0.247059)
game.Lighting.Atmosphere.Haze = 5
script["Rain Sound Effect"].Volume = 0.3
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.8
game.Lighting.Atmosphere.Color = Color3.new(0, 0, 0)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0, 0)
game.Lighting.Atmosphere.Haze = 2.75
script["Rain Sound Effect"].Volume = 0.4
game.Lighting.Brightness = 0
game.Lighting.EnvironmentDiffuseScale = 0
game.Lighting.Ambient = Color3.new(0, 0, 0)
game.Lighting.OutdoorAmbient = Color3.new(0, 0, 0)
end
else
if L == false then
L = true
game.Lighting.Atmosphere.Density = 0.7
game.Lighting.Atmosphere.Color = Color3.new(0.129412, 0.188235, 0.247059)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.133333, 0.247059)
game.Lighting.Atmosphere.Haze = 5
script["Rain Sound Effect"].Volume = 0.3
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.5
game.Lighting.Atmosphere.Color = Color3.new(0.262745, 0.376471, 0.498039)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.266667, 0.498039)
game.Lighting.Atmosphere.Haze = 1
script["Rain Sound Effect"].Volume = 0.2
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.3
game.Lighting.Atmosphere.Color = Color3.new(0.396078, 0.568627, 0.74902)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.4, 0.74902)
game.Lighting.Atmosphere.Haze = 0.1
script["Rain Sound Effect"].Volume = 0.1
task.wait(0.15)
game.Lighting.Atmosphere.Density = 0.25
game.Lighting.Atmosphere.Color = Color3.new(0.529412, 0.756863, 1)
game.Lighting.Atmosphere.Decay = Color3.new(0, 0.533333, 1)
game.Lighting.Atmosphere.Haze = 0.01
script["Rain Sound Effect"].Volume = 0
game.Lighting.Brightness = 4
game.Lighting.EnvironmentDiffuseScale = 1
game.Lighting.Ambient = Color3.new(0.243137, 0.243137, 0.243137)
game.Lighting.OutdoorAmbient = Color3.new(0.27451, 0.27451, 0.27451)
end
end
end
end
end
Here’s the script that causes the lightning sounds.
local players = game:GetService('Players')
local maxDistance = 241
local L = true
while task.wait(0.1) do
for i, player in players:GetPlayers() do
if player.Character then
if player:DistanceFromCharacter(script.Parent.Position) < maxDistance then
if L == true then
L = true
if math.random(1,3) == 1 then
local AssetFolder = script
local Sfx1 = AssetFolder:GetChildren()[math.random(1, #AssetFolder:GetChildren())]
local Sfx = Sfx1:Clone()
game.Lighting.Brightness = math.random(3,10)
Sfx.Parent = script
Sfx.Playing = true
Sfx.PlaybackSpeed = math.random(90,110)/100
Sfx.Volume = math.random(40,60)/100
task.wait(0.2)
game.Lighting.Brightness = 0
task.wait(math.random(1,10))
Sfx:Destroy()
end
end
end
end
end
end
The issue here, I struggle a little explaining it, but it works outside said area, without even going inside first. (Also as show in the following video.)
EPILEPSY WARNING
(Applies at 0:08, also where the bug starts.)
I don’t know how I could physically fix the script, but it seems to only happen when I’m too far from the part that it unloads from the workspace. I have searched a little bit the forum for answers, but nothing helped. (Edit : It works perfectly fine in roblox studio.)
If anyone has a solution, or a post to redirect me to, I’d be glad!
Thank you!
