Changing lighting on the client side when stepping into different zones

Hello,

I’m trying to create a script which changes the ambient lighting based on which zone you are in (part located in the workspace). I’ve gotten everything to work properly but the lighting changes on the server side for all players.

I’ve been trying to use remote events but I’m a little confused on how to keep it on the client side.

Script in StarterCharacterScripts


Lighting = game:GetService('Lighting')
local TweenService = game:GetService("TweenService")
local player = game.Players.LocalPlayer
local City = false
local County = false

game.Workspace.GameNetwork.Zones.City.Touched:Connect(function(partTouched)
	if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
		City = true
		local player = game.Players:FindFirstChild(partTouched.Parent.Name)
		local playerGui = player:FindFirstChild("PlayerGui")
		local Frame = playerGui:WaitForChild("Main"):WaitForChild("LocationFrame")
		local Accent = Frame:WaitForChild("Accent")
		local Welcome = Frame:WaitForChild("WelcomeLabel")
		local Location = Frame:WaitForChild("LocationName")
		local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.In)
		Location.Text = "City Of Cambridge"
		local LocationTween = TweenService:Create(Location, TweenInfo, {TextTransparency = 0})
		local WelcomeTween = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 0})
		local AccentTween = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 0})
		LocationTween:Play()
		WelcomeTween:Play()
		AccentTween:Play()
		task.wait(2)
		local LocationTweenOut = TweenService:Create(Location, TweenInfo, {TextTransparency = 1})
		local WelcomeTweenOut = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 1})
		local AccentTweenOut = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 1})
		LocationTweenOut:Play()
		WelcomeTweenOut:Play()
		AccentTweenOut:Play()
	end
end)

game.Workspace.GameNetwork.Zones.City.TouchEnded:Connect(function(partTouched)
	if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
		City = false
	end
end)

game.Workspace.GameNetwork.Zones.County.Touched:Connect(function(partTouched)
	if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
		County = true
		local player = game.Players:FindFirstChild(partTouched.Parent.Name)
		local playerGui = player:FindFirstChild("PlayerGui")
		local Frame = playerGui:WaitForChild("Main"):WaitForChild("LocationFrame")
		local Accent = Frame:WaitForChild("Accent")
		local Welcome = Frame:WaitForChild("WelcomeLabel")
		local Location = Frame:WaitForChild("LocationName")
		local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.In)
		Location.Text = "Wasaga Beach"
		local LocationTween = TweenService:Create(Location, TweenInfo, {TextTransparency = 0})
		local WelcomeTween = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 0})
		local AccentTween = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 0})
		LocationTween:Play()
		WelcomeTween:Play()
		AccentTween:Play()
		task.wait(2)
		local LocationTweenOut = TweenService:Create(Location, TweenInfo, {TextTransparency = 1})
		local WelcomeTweenOut = TweenService:Create(Welcome, TweenInfo, {ImageTransparency = 1})
		local AccentTweenOut = TweenService:Create(Accent, TweenInfo, {BackgroundTransparency = 1})
		LocationTweenOut:Play()
		WelcomeTweenOut:Play()
		AccentTweenOut:Play()
	end
end)

game.Workspace.GameNetwork.Zones.County.TouchEnded:Connect(function(partTouched)
	if partTouched and partTouched.Parent and partTouched.Parent:FindFirstChildOfClass("Humanoid") then
		County = false
	end
end)

while true do
	wait()
	if City == true then
		local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local Brightinfo = TweenInfo.new(1.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local Night = false
		local Day = false
		if Lighting.ClockTime >= 17 or Lighting.ClockTime < 6 then
			Night = true
		else
			Day = true
		end
			if Night == true then
				local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 1})
				BrightTween:Play()
				BrightTween.Completed:Wait()

				local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(52,52,52)})
				BrightTween:Play()
				BrightTween.Completed:Wait()
			elseif Day == true then
				local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 2})
				BrightTween:Play()
				BrightTween.Completed:Wait()

				local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(71, 71, 71)})
				BrightTween:Play()
				BrightTween.Completed:Wait()
			end
		end
	if County == true then
		local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local Brightinfo = TweenInfo.new(1.8, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false, 0)
		local Night = false
		local Day = false
		if Lighting.ClockTime >= 17 or Lighting.ClockTime < 6 then
			Night = true
		else
			Day = true
		end

		if Night == true then
				local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 1})
				BrightTween:Play()
				BrightTween.Completed:Wait()

				local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(32,32,32)})
				BrightTween:Play()
				BrightTween.Completed:Wait()
		elseif Day == true then
				local BrightTween = TweenService:Create(game.Lighting, Brightinfo, {Brightness = 2})
				BrightTween:Play()
				BrightTween.Completed:Wait()

				local BrightTween = TweenService:Create(game.Lighting, info, {Ambient = Color3.fromRGB(78, 78, 78)})
				BrightTween:Play()
				BrightTween.Completed:Wait()
			end
		end
	end

Any help would be greatly appreciated.

i have a script that does this, you dont need remote events at all if you wanted to keep it client. Just simply look for touch and change the lighting properties accordingly, but if you wanted it to not be so sudden, you can do a 1 second tween to change the properties over.

local LightParts = workspace:WaitForChild("LightParts")
local Lighting = game:GetService("Lighting")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local LightingPresets = {
	Spawn = {
		Brightness = 2.5, 
		ClockTime = 14, 
		FogEnd = 800, 
		Ambient = Color3.fromRGB(200, 200, 220), 
		OutdoorAmbient = Color3.fromRGB(180, 180, 201), 
		ExposureCompensation = 0.2, 
		ColorShift_Top = Color3.fromRGB(220, 200, 180),
		ColorShift_Bottom = Color3.fromRGB(240, 230, 210) 
	},
	Default = {
		Brightness = 3,
		ClockTime = 14.5,
		FogEnd = 5000,
		Ambient = Color3.fromRGB(67, 67, 67),
		ColorShift_Top = Color3.fromRGB(0,0,0),
		ColorShift_Bottom = Color3.fromRGB(0,0,0), 
		OutdoorAmbient = Color3.fromRGB(70,70,70),
		ExposureCompensation = 0, 
	}
}

local function ApplyLighting(settings)
	for property, value in pairs(settings) do
		Lighting[property] = value
	end
end

local activeZone = nil 

for _, part in ipairs(LightParts:GetChildren()) do
	if part:IsA("BasePart") then
		part.Touched:Connect(function(hit)
			local character = LocalPlayer.Character
			if character and hit:IsDescendantOf(character) then
				activeZone = part.Name
				local settings = LightingPresets[part.Name] or LightingPresets.Default
				ApplyLighting(settings)
			end
		end)
		part.TouchEnded:Connect(function(hit)
			local character = LocalPlayer.Character
			if character and hit:IsDescendantOf(character) then
				if not activeZone then
					ApplyLighting(LightingPresets.Default)
				end
				activeZone = nil
			end
		end)
	end
end

this script is in starterplayers, feel free to use i!