Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing the ambient to a certain value?

Hi!! my friend made a script for a game we're working on- when you step on the brick, a script in StarterCharacterScripts will find the values inside that brick (which are IDs for the skybox textures) and apply it to the skybox.

There's a town area in this game that's supposed to always be night time. Changing the skybox to a night skybox would help with that, but I also want the lighting to be dark as well.

So, I figured adding two new values (for Ambient and OutdoorAmbient) to this would help.

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local debounce = true


local touchDetect = humanoid.Touched:Connect(function(hit,limb)
	if debounce == true then
		if hit:FindFirstChild("SkyboxUp") then
			
			game.Lighting.Sky.SkyboxBk = hit.SkyboxBk.Value
			game.Lighting.Sky.SkyboxDn = hit.SkyboxDn.Value
			game.Lighting.Sky.SkyboxFt = hit.SkyboxFt.Value
			game.Lighting.Sky.SkyboxLf = hit.SkyboxLf.Value
			game.Lighting.Sky.SkyboxRt = hit.SkyboxRt.Value
			game.Lighting.Sky.SkyboxUp = hit.SkyboxUp.Value
			game.Lighting.Ambient = Color3.new(hit.Ambient.Value)
			game.Lighting.OutdoorAmbient = Color3.new(hit.OutdoorAmbient.Value)
			
			debounce = false
			wait(0.2)
			debounce = true
		end
	end
end)

The two lines toward the bottom are what I added to my friend's script (ambient and outdoor ambient.)

I tested this ingame, and rather than being set to the values I put in, the ambient and outdoorambient just change to 0,0,0. There's no errors in the output, though. Anyone know how to fix this? I haven't scripted anything in ROBLOX in a while, so I kinda forgot a few things haha-

1 answer

✓ Accepted answer

Make sure the ambient values are Color3 values then

Change this code from this:

game.Lighting.Ambient = Color3.new(hit.Ambient.Value)
game.Lighting.OutdoorAmbient = Color3.new(hit.OutdoorAmbient.Value)

To this:

game.Lighting.Ambient = hit.Ambient.Value
game.Lighting.OutdoorAmbient = hit.OutdoorAmbient.Value

This discussion is preserved as it was. New answers, comments, and votes are closed.