Hello, I have a problem with the following script and it is that when I touch another part of the 7 that I have in the biome, the fog disappears and I really don’t know what to do to prevent this from happening since I haven’t found a more effective and optimized way. to put fog in a single biome, if anyone can help me I would greatly appreciate it
-- local Model = game.Workspace.FOGbosqueNadie:GetDescendants()
local Lighting = game.Lighting
local tweenService = game:GetService("TweenService")
local transitionColor = Color3.fromRGB(0, 0, 71)
local cooldownTime = 30
local playerCooldowns = {}
local function ApplyFogValuesWithFade()
local tweenInfo = TweenInfo.new(5)
local tween = tweenService:Create(Lighting.Atmosphere, tweenInfo, {Density = 0.50, Offset = 0})
tween:Play()
end
local function RestoreFogValuesWithFade()
local tweenInfo = TweenInfo.new(5)
local tween = tweenService:Create(Lighting.Atmosphere, tweenInfo, {Density = 0.188, Offset = 0.104})
tween:Play()
end
local function UpdateAtmosphereColorWithTransition()
local tweenInfo = TweenInfo.new(120)
local tween = tweenService:Create(Lighting.Atmosphere, tweenInfo, {Color = transitionColor})
tween:Play()
end
local function HandleCooldown(playerName)
playerCooldowns[playerName] = tick()
wait(cooldownTime)
playerCooldowns[playerName] = nil
end
for _, part in ipairs(Model) do
if part:IsA("BasePart") then
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local playerName = player.Name
local currentTime = tick()
if playerCooldowns[playerName] and currentTime - playerCooldowns[playerName] < cooldownTime then
return
end
ApplyFogValuesWithFade()
wait(20)
UpdateAtmosphereColorWithTransition()
end
end)
part.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local playerName = player.Name
HandleCooldown(playerName)
RestoreFogValuesWithFade()
end
end)
end
end