How to change the lighting properties for each area in a game for different players

I am currently making a game where in one area the sun rays will need to stay bright and blinding, but once the player moves/teleports to another area of the map the sun rays will dim down a good bit and become far less as bright.

I will also like to know how to do this to other lighting properties such as brightness, fog thickness, and even possibly the skybox.

Really the affect I am trying to achieve is for a player to be in one part of the map experiencing a high concentration of sun rays or weaker fog, and than another player being on the other side of the map with sunrays of a less intensity or even much thicker fog.

I am not really much a scripter so If you can keep it simple enough for me to understand.

This is an edit Here is the game I used it on
https://www.roblox.com/games/6006043193/The-Christmas-Story?refPageId=7f4af41b-0285-42c9-a51b-371f2bf1a43d

6 Likes

This is a question for scripting section actually.
Some ppl could say that use Region3 and Raycasting. I prefer checking events.
The player uses a door? the player use a button to teleport? Maybe when the player touch the floor of that area… idk depends on you. Any of those events are useful.
Its just about, using that event to change all those lighting properties on a local script

For example. You have this LocalScript in StarterPlayerScripts. And this is what Lighting looks like using Atm,Sky,Bloom,Blur,CC, and Sunrays
image

-- Lighting Main Parent
local sun = game.Lighting

-- Parenting the Atmosphere
local atm = sun.Atmosphere
-- Parenting ColorCorrection FX
local CC = sun.ColorCorrection

-- (Optionals, parent the ones you need)
-- Parent Blur
-- Parent Bloom
-- Parent SunRays

-- Changing Parameters
-- Now you can change any property inside those
-- Accesing Main Lighting and changing clock time
sun.ClockTime = 15
-- Accessing Main Lighting and changing ExporuseCompensation
sun.ExposureCompensation = 1
-- Brightness
sun.Brightness = 9

-- Accessing Atmosphere and changing Density of fog
atm.Density = 0.8
-- As other params
atm.Glare = 6
atm.Haze = 1

-- Accesing ColorCorrection FX and changing color
CC.TintColor = Color3.fromRGB(100, 140, 100)

If you change all those paramentes inside that LocalScript, the changes will be visible only for that player, and not anyone else in server.
So, by triggering an event from opening a door, or teleporting with a button or something (on touch whatever)
You need to access this LocalScript and change those parameters based on the lighting you want for each area.
You will probably need a RemoteEvent that reads the event on Server, and FireClient() to change the parameters on this script using a function connected to that RemoteFunction

You can send values thru the RemoteEvent, so the function will be able to set different lightings depending on the room you are sending (of course you need to create the RemoteEvent, I called this one LightEvent)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("LightEvent")

local function ChangeRoomLight(Time, Bright, Den)
	sun.ClockTime = Time
	sun.Brightness = Bright
	atm.Density = Den
end
RemoteEvent.OnClientEvent:Connect(ChangeRoomLight) 

My explanation could be confusing, sorry for that. Btw, those scripts are not going to work fine if you dont set the values and connections manually, Im just giving you a brief example how to do it.
We’ll be here if u have more doubts :3

3 Likes

Thank you, but I’m not much of a scripter, so I can’t quite figure out how to put it together.
Using this teleportation script can you help me change the sun rays intensity when the player teleports.

place = CFrame.new(-719.318, 525.448, 340.759) -- Where you want the player to go on touched
script.Parent.Touched:connect(function(p)--Creating the function
	local humanoid = p.Parent:findFirstChild("Humanoid")--Trying to find the humanoid
	if (humanoid ~= nil) then -- Checking if what touched it IS a player.
		humanoid.Torso.CFrame = place -- Moves the torso to what is specified in the place variable
	end
end)--Ending the fuction, if you see on the function line above there is an unclosed parenthesis that I am closing here.

It would also be nice if I could change multiple lighting properties like the ones you listed in the same teleport.

1 Like

Hiwi!

Okie, I made your script, and I want to help you to connect it. Just follow these steps.

BTW, I checked your Teleport script, and its good, but its triggering at least 4 times… And thats not good. (Brief explanation)
The characters are made of many parts, and the Touch event, gets the Touch Event PER part inside the character. Everytime a part is found your function is cheking the part’s parent to find a Humanoid… And it will find a Humanoid maybe +16 times… Triggering “something” +16 times… Which you and nobody wants to that happen…

So I changed it completely. I dont know the “best” approach. I just use this approach cause I like it. I only compare if the Hit part.Name its a HumanoidRootPart. We have only 1 HumanoidRootPart inside the characters, so its convinient. Triggers only once.

1- The only one inconvinient, is that you gotta make a “tall” invisible boundary box to check the Touch event, heres some pics: (make it enough tall to hit the full body, and you can make it totally invisible, and keep a small part or something you want as a “Teleport model”)

2- You need to create a RemoteEvent and place it inside ReplicatedStorage, name that RemoteEvent “LightEvent”
And you need to place at least the SunRays inside lighting.

image

3- Place this Script inside the BoundaryBox:

-- Services
-- Parent ReplicatedStorage
local RepS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- RemoteEvents
local LE = RepS:WaitForChild("LightEvent")

-- Coordinates to TP
local place = CFrame.new(-719.318, 525.448, 340.759)

-- On touch a boundary invisible box. Should be tall enough to be touched by the HumanoidRootPart
script.Parent.Touched:connect(function(hit)
	if hit.Name == "HumanoidRootPart" then -- Make sure the function trigger ONLY ONCE, only when the HumanoidRootPart is found
		local hitPlayer = Players:GetPlayerFromCharacter(hit.Parent) -- Get the Player instance from HRP touched
		hitPlayer.Character.HumanoidRootPart.CFrame = place -- Moving the HumanoidRootPart
		LE:FireClient(hitPlayer) -- Fire Client Event for only the player who touched the box
	end
end)

4- Place this LocalScript inside StarterPlayerScripts

-- Services
-- Parent ReplicatedStorage
local RepS = game:GetService("ReplicatedStorage")
local LE = RepS:WaitForChild("LightEvent")

-- RemoteEvents
local LE = RepS:WaitForChild("LightEvent")

-- Lighting Main Parent
local sun = game.Lighting
-- Parenting the Atmosphere
local sunRays = sun.SunRays

-- Initial SunRays Values for the player when joins
-- Change them to anything you want
sunRays.Intensity = 1
sunRays.Spread = 0.6

-- Function, it will change the Intensity and Spread of SunRays
local function mainLight()
	sunRays.Intensity = 0 -- Change this values to anything u want
	sunRays.Spread = 0 -- Change this values to anything u want
end
-- Listener, when Server calls the LightEvent it will fire the function above
LE.OnClientEvent:Connect(mainLight)

5- Change values inside the LocalScript to the ones you want for SunRays.
Theres a part in the LocalScript called – Initial SunRays values. Those are the initial values the player gets when join the server. And change the sunRays.Intensity and Spread values inside the function mainLight() to the ones you want after the player teleports.
Just change the number to the values you want. from 0 to 1. I just used total 0 after the player Teleports. Customize it as you wants.

image

If you did everything right, thats it! If you need to connect more parameters to change, feel free to ask, I can show you how u can change any. Good luck, cya! :3

20 Likes

Thank you so much, I wish their was a way to repay you for helping me so much. Ill leave a link to the game I’m using it on once I’m done.

2 Likes

Hello Dev_Peashie, :wave:

I’m a builder in Roblox Studio, recently I started to learn to script for my game, but I have a question about this. How I can make this, same thing but back to the normal (i mean custom light to initial light)

Thank you, for your help! :grinning: