Why does my script only seem to affect one player

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
1 Like

The problem is because it’s a LocalScript. LocalScripts are used to affect one player while “ServerScripts” or “Scripts” influence everyone.

hm, how might i make this work for everyone?

Make it a script and put it in the ServerScriptService or Workspace.
image

will there be a problem with using local player?

Can you also make a video showing me how the system works, because Scripts usually need modifications.

absoultely give me one minute to show you

Yes, Local Player works only for local scripts, in ServerScripts there are other methods to find players.


and it should only fog for that player also

So, you want to make a part and when a player gets through it everything becomes foggy for everyone right?

yes, but it should only appear foggy for anyone who is actually inside the part, and when you leave it will unfog

Can you also send me the clip where it doesn’t work for the other player?

it seems to be working in studio but not in roblox

ive got one of my friends on and the fog isnt working for either of us

im not sure how i can record his pov

now its working in roblox aswell
its like random it will or wont

now its not
we just died in the fog and it stopped alltogether

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

just into the original script?