I currently have a script that holds a remote event for an attack skill im making. In the skill it created dark fog through the lighting and after the skill finishes, returns it back to the normal lighting. This script is server-sided as I want everyone to be able to witness it.
The problem that im facing is that when more than one person uses this skill, it messes up the process of the dark fog closing in on the player. Ive tried multiple things including bools and while loops but couldn’t seem to figure it out on my own. Here is the script for the event along with a representation of what happens when the skill is activated.
In the script below you will find a note where my problem is at:
se.OnServerEvent:Connect(function(Player)
local atmos = game.Lighting
local shrimp = rs:WaitForChild("Shrimp"):Clone()
local fire = rs:WaitForChild("Attacks").CPart.Attachment
local fire1 = fire.ParticleEmitter:Clone()
local fire2 = fire.Spike:Clone()
local firesound = rs:WaitForChild("AttSounds").ShrimpAttack
local opera = rs:WaitForChild("AttSounds").opera
atmos.FogEnd = 600
atmos.FogColor = Color3.fromRGB(0,0,0)
shrimp:Clone()
opera:Play()
shrimp.Parent = Player.Character:WaitForChild("HumanoidRootPart")
shrimp.N1.CFrame = Player.Character:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0,25,20)
shrimp.N1.CFrame = shrimp.N1.CFrame * CFrame.fromEulerAnglesXYZ(1.3,0,1.55)
local weld = Instance.new("WeldConstraint")
weld.Parent = Player.Character:WaitForChild("HumanoidRootPart")
weld.Part0 = Player.Character:WaitForChild("HumanoidRootPart")
weld.Part1 = shrimp.N1
for i, v in pairs(shrimp:GetChildren()) do
while v.Transparency > 0 do
v.Transparency = v.Transparency - .25
task.wait()
end
end
for i = 1, 50 do -- This is where my problem begins, this creates the fog through lighting.
task.wait()
atmos.FogEnd = atmos.FogEnd - 10
end
fire1:Clone()
fire2:Clone()
fire1.Parent = shrimp.Mouth
fire2.Parent = shrimp.Mouth
firesound:Play()
task.wait(7)
fire1:Remove()
fire2:Remove()
shrimp:Destroy()
firesound:Stop()
while atmos.FogEnd == 100 and atmos.FogEnd ~= 600 do
for i = 1, 50 do
task.wait()
atmos.FogEnd = atmos.FogEnd + 10
end
end
atmos.FogEnd = 2000
atmos.FogColor = Color3.fromRGB(152,155,162)
for i = 1,20 do
task.wait(0.05)
opera.Volume = opera.Volume - 0.05
end
opera:Stop()
opera.Volume = 1
end)
Normally, the event would play out like this, eventually with the lighting returning to normal (Can’t show in clip due to length settings):
Have you tried checking if the fog had the desired FogEnd value ?
for i = 1, 50 do -- This is where my problem begins, this creates the fog through lighting.
task.wait()
if atmos.FogEnd > DESIRED FOGEND then --Check if fog needs to be lowered
atmos.FogEnd -= 10 -- "i -= f" is a shorter way of doing "i = i - f"
elseif atmos.FogEnd < DESIRED FOGEND then --If we lowered it too much, we want to clamp it to the desired FogEnd
atmos.FogEnd = DESIRED FOGEND
end
end
Well theres a local script that activates the server event, so whenever any player presses the key, that event will fire. If that means that it will speed it up, is there a better way to do it?
Make a different script that only handles all the lighting effects based on values located in a configuration folder (optional but recommended).
For the fog :
local desiredFog = script.configuration.DesiredFog --Your number value, can be anywhere
local atmos = game.Lighting
while task.wait() do
if atmos.FogEnd > desiredFog.Value then --Check if fog needs to be lowered
atmos.FogEnd -= 10 -- "i -= f" is a shorter way of doing "i = i - f"
elseif atmos.FogEnd < desiredFog.Value then --If we lowered it too much, we want to clamp it to the desired FogEnd
atmos.FogEnd = desiredFog.Value
end
end
I haven’t tested this script yet, tell me if it works
Could I put this in a separate script under the SAME remote event?
local desiredFog = script.configuration.DesiredFog --Your number value, can be anywhere
local atmos = game.Lighting
while task.wait() do
if atmos.FogEnd > desiredFog.Value then --Check if fog needs to be lowered
atmos.FogEnd -= 10 -- "i -= f" is a shorter way of doing "i = i - f"
elseif atmos.FogEnd < desiredFog.Value then --If we lowered it too much, we want to clamp it to the desired FogEnd
atmos.FogEnd = desiredFog.Value
end
end
I feel I read somewhere you cant use the same remote event for two different things but I want to be sure.
Okay so this is a lot closer to the goal im aiming for and I tweaked a little bit of your script to fit it, but the new issue is that if the fog is actively enclosing and someone else activates the remote event it will restart the fog instead of just ignoring it till it reaches desiredEndFog’s value.
This is what I tried to do to combat that but I believe the script is running to fast to where I believe it takes off (-= 10) once and then returns, or something of that sort. I’m not sure why.
This is how I have tweaked the script:
local startFog = 600
local desiredEndFog = script:WaitForChild("Configuration").End
local atmos = game.Lighting
local rs = game:GetService("ReplicatedStorage")
local se = rs:WaitForChild("ShrimpEvent")
se.OnServerEvent:Connect(function()
while task.wait() do
if atmos.FogEnd < startFog then return -- Here is where I believe the issue is
elseif atmos.FogEnd > desiredEndFog.Value then
atmos.FogEnd -= 10 -- Starts at startFog but takes off leaving it at 590, then above line returns.
elseif atmos.FogEnd < desiredEndFog.Value then
atmos.FogEnd = desiredEndFog.Value
elseif atmos.FogEnd == desiredEndFog.Value then
return
end
end
end)