Change lighting for local player on death

I’m making a script where if a player dies, it changes the ClockTime and other lighting things for the client. For some reason in my script, when the player dies, no lighting changes at all and there is no output error.

local Lighting = game:GetService("Lighting")
local Ambient = Lighting.Ambient
local OutdoorAmbient = Lighting.OutdoorAmbient
local FogColor = Lighting.FogColor
local FogEnd = Lighting.FogEnd
local FogStart = Lighting.FogStart
local Brightness = Lighting.Brightness
local ClockTime = Lighting.ClockTime --old settings for lighting pre-change

game.Lighting.ClockTime = 1
game.Lighting.Brightness = 0
game.Lighting.Ambient = Color3.new(0, 0, 0)
game.Lighting.OutdoorAmbient = Color3.new(0, 0, 0)
game.Lighting.FogStart = 0
game.Lighting.FogEnd = 20
game.Lighting.FogColor = Color3.new(0, 0, 0) --changes lighting settings

game.Players.PlayerAdded:Connect(function(player) 
	player.CharacterAdded:Connect(function(character) 
		character:WaitForChild('Humanoid').Died:Connect(function()
			ClockTime = ClockTime
			Ambient = Ambient
			OutdoorAmbient = OutdoorAmbient
			FogEnd = FogEnd
			FogStart = FogStart
			FogColor = FogColor
			Brightness = Brightness
			script:Destroy() --on death what should be happening is it goes back to the old settings
		end)
	end)
end)

This is on a LocalScript in PlayerGui. I’ve tried to make the values for the bottom third part numbers rather than variables like “ClockTime” but nothing happened at all, still not even anything in the output.

Does that part of the script work? If so it may be the functions your calling here:

I believe just doing Humanoid.Died:Connect(function() is all you need, rest is extra.

That (middle) part of the script works. I changed the bottom part to this:

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
	ClockTime = 9
	Ambient = Ambient
	OutdoorAmbient = OutdoorAmbient
	FogEnd = FogEnd
	FogStart = FogStart
	FogColor = FogColor
	Brightness = Brightness
	script:Destroy()
end)

But, now I get an error that says:

Humanoid is not a valid member of Model "Workspace.ItchingPowder123"

No errors now, but the lighting still doesn’t change.

I think I know why,

Instead of doing “clocktime = clocktime” do for example “game.lighting.clocktime = clocktime”

1 Like

You change your clocktime so the local changes but then you = it to itself in the end its not changing.

1 Like