Yes, put it in your local script.
well it all seems to be working fine however my only issue is if the player dies in the fog when they respawn it goes back to day time and removes fog as normal but the fog wont work again
Well, to fix that, if the player’s character is not found then use return to keep ending the loop until the player is found
while true do
if not char then
return
end
okey! is that before the wait or after
while true do
task.wait(1)
RunService.Heartbeat:Wait()
if not char then
return --Stops the loop
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
the problem seems to be occuring as it was
if you died in the fog it breaks and doesnt work again
I tested it myself and it worked.
Do you have a “TheFogValue” in your character?
oh yes i forgot i added that using another script
its part of my playerjoin script
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
if not char:FindFirstChild("theFog") then
local theFog = Instance.new("BoolValue", char)
theFog.Name = "theFog"
end
if not plr.PlayerGui:WaitForChild("Background").IsPlaying then
plr.PlayerGui:WaitForChild("Background"):Play()
end
plr.PlayerGui:WaitForChild("Background").Volume = 0.5
plr.PlayerGui:WaitForChild("Fog").Volume = 0
char.Humanoid.Died:Connect(function()
game:GetService("TweenService"):Create(plr.PlayerGui:WaitForChild("Background"),TweenInfo.new(0.5), {Volume = 0}):Play()
wait(0.5)
plr.PlayerGui:WaitForChild("Background"):Stop()
end)
end)
end)
Try this in your original script and tell me if it’s good or not.
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
print("done")
RunService.Heartbeat:Wait()
if not char then
return
end
local condition = #workspace:FindPartsInRegion3WithWhiteList(region, {char}) > 0
--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(game.Lighting, TweenInfo.new(1), {ClockTime = condition and 0 or 14}):Play()
end
well i noticed theres alot of prints
also still the death glitch occurs and performance seems to drop the longer i play
my fan is gettting a little bit louud now
yes, it’s because while loops drop performance
and maybe it’s because of the prints
unfortunately thjis doesnt change anthing