How can I make a lighting like in Baldi's Basics Plus?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to make lighting like in Baldi’s Basics Plus. Here’s a screenshot which I found on wiki

  2. What is the issue? Include screenshots / videos if possible!
    I don’t know ANYTHING about scripting lighting.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I was searching everywhere, but only found a video showcasing it but not showing the script.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

7 Likes

Using CollectionService, you can easily do a Baldi like lighting system by adding tags to objects that emits light and objects that receives it.

You can easily set attributes on parts that you tag as “LightEmitter” so you can edit them for your crazy needs like schoolhouse escape or flickering the lights with The Test.
image

Here is a simple code to achieve that effect using only parts. It’s up to you to edit it so this supports textures/decals. I also provided a small test place below so you can start experimenting with it. Have fun!

local CollectionService = game:GetService("CollectionService")

-- The complexity of this code is O(n * m)
-- If you do add alot of lights, be sure to call this function when needed.
local function UpdateLights()
	
	for _,receiver:Part in CollectionService:GetTagged("LightReceiver") do
		-- starts black
		local finalColor = Color3.new(0,0,0)

		for _,emitter in CollectionService:GetTagged("LightEmitter") do
			
			-- Calculate the distance
			local emitterRange = emitter:GetAttribute("Range") :: number
			local distance = (receiver.Position - emitter.Position).Magnitude
			local distancePercentage = (emitterRange-distance) / emitterRange

			-- Distance is too far, skip
			if (distance > emitterRange)  then 
				continue
			end

			local emitterColor = emitter:GetAttribute("Color") :: Color3
			local emitterIntensity = emitter:GetAttribute("Intensity") :: number
			
			-- Calculate each color depending on the distance
			local r = math.clamp(finalColor.R + emitterColor.R * distancePercentage, 0,1)
			local g = math.clamp(finalColor.G + emitterColor.G * distancePercentage, 0,1)
			local b = math.clamp(finalColor.B + emitterColor.B * distancePercentage, 0,1)

			finalColor = Color3.new(r,g,b)
		end

		receiver.Color = finalColor
	end
end

-- In the original Baldi's Basics Game,
--  lights are updated only when they are changed.
-- For example, when the player looks at Timmy The Test, 
--  it calls FlickerLights which update the lights
-- In this example, the lights are updated continously so you can run 
-- on Studio and move the parts to see the changes in real time
while true do
	UpdateLights()
	task.wait()
end


Place1.rbxl (56,6 Ko)

5 Likes

what are you actually trying to achieve? this lighting can easily be accomplished without any scripts, just point, surface, etc lights. roblox already has light objects, you may just need to tweak the lighting settings to get the correct look

1 Like

I edited my message just in case you readed it before)

3 Likes

Thank you! This works just like I need.

2 Likes

The only problem though is that decals/textures don’t get affected. If I do the tag it will even break the whole lighting thing.

Also this happened when I tried to make the lighting appear on a character for my game

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.