this localscript is located in starterplayerscripts and when you enter a part called Fog it effectively makes everything foggy
but when i tested with another player it only worked for him and not me
im not sure why
local Players = game:GetService("Players")
local Lighting = game:GetService("Lighting")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local regionPart = game.Workspace:WaitForChild("Fog")
local size = regionPart.Size * 0.5
local pos = regionPart.Position
local region = Region3.new(pos - size, pos + size)
while true do
RunService.Heartbeat:Wait()
if not char then
char = player.Character or player.CharacterAdded:Wait()
end
local condition = #workspace:FindPartsInRegion3WithWhiteList(region, {char}) > 0
char:WaitForChild("theFog").Value = condition and true or false
--Lighting.Atmosphere.Density = condition and 0.75 or 0
game:GetService("TweenService"):Create(Lighting.Atmosphere, TweenInfo.new(1), {Density = condition and 0.75 or 0}):Play()
game:GetService("TweenService"):Create(player.PlayerGui:WaitForChild("Fog"), TweenInfo.new(1), {Volume = condition and 0.8 or 0}):Play()
game:GetService("TweenService"):Create(player.PlayerGui:WaitForChild("Background"), TweenInfo.new(1), {Volume = condition and 0 or 1}):Play()
game:GetService("TweenService"):Create(game.Lighting, TweenInfo.new(1), {ClockTime = condition and 0 or 14}):Play()
end
I think you should try adding task.wait() here because loops can’t be played so many times without a break.
while true do
task.wait(1)
RunService.Heartbeat:Wait()
if not char then
char = player.Character or player.CharacterAdded:Wait()
end
local condition = #workspace:FindPartsInRegion3WithWhiteList(region, {char}) > 0
char:WaitForChild("theFog").Value = condition and true or false
--Lighting.Atmosphere.Density = condition and 0.75 or 0
game:GetService("TweenService"):Create(Lighting.Atmosphere, TweenInfo.new(1), {Density = condition and 0.75 or 0}):Play()
game:GetService("TweenService"):Create(player.PlayerGui:WaitForChild("Fog"), TweenInfo.new(1), {Volume = condition and 0.8 or 0}):Play()
game:GetService("TweenService"):Create(player.PlayerGui:WaitForChild("Background"), TweenInfo.new(1), {Volume = condition and 0 or 1}):Play()
game:GetService("TweenService"):Create(game.Lighting, TweenInfo.new(1), {ClockTime = condition and 0 or 14}):Play()
end