FogColor not changing

I have a local script (in StarterCharacterScripts) that changes the skybox and fog color depending on where the player is on the map. The skybox changing part seems to work quite well, but the color of the fog always remains the same.

local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local HRP = Char:WaitForChild("HumanoidRootPart")
local SkyBricks = workspace:WaitForChild("SkyBricks")
local SkyFolder = script:WaitForChild("Skyboxes")

local FoundSky = false

local colors = { -- The values are all set to really red as a test. The fog still doesn't change to red anyway.
	["City"] = {255, 0, 0},
	["Mountains"] = {255, 0, 0},
	["SomeOtherPlace"] = {255, 0, 0},
	["Default"] = {175, 206, 212}
}

local function ChangeSky(skybox)
	if game.Lighting:FindFirstChildOfClass("Sky") then
		game.Lighting:FindFirstChildOfClass("Sky"):Destroy()
	end
	
	skybox.Parent = game.Lighting
end

--------------------------------------------------

repeat wait(0.1) until #SkyBricks:GetChildren() == 14 

HRP.Touched:Connect(function(hit)
	if hit.Parent == SkyBricks then
		ChangeSky(SkyFolder:FindFirstChild(hit.Name) and SkyFolder:FindFirstChild(hit.Name):Clone() or SkyFolder.Default:Clone())
	end
end)

HRP.TouchEnded:Connect(function(hit)
	if hit.Parent == SkyBricks then
		ChangeSky(SkyFolder.Default:Clone())
	end
end)

for _, v in pairs(SkyBricks:GetChildren()) do
	for _, part in pairs(v:GetTouchingParts()) do -- get every part touching the skybrick
		if part == HRP then -- if the part belonged to a character then
			FoundSky = true
			ChangeSky(SkyFolder:FindFirstChild(v.Name) and SkyFolder:FindFirstChild(v.Name):Clone() or SkyFolder.Default:Clone())
			game.Lighting.FogColor = Color3.fromRGB(unpack(colors[v.Name])) -- where i believe it's failing
			break
		end
	end
end

if not FoundSky then
	ChangeSky(SkyFolder.Default:Clone())
end

No errors in the output, nothing telling me why this is happening. pls help

2 Likes

What is the fog distance? If there is no fog, the fog color change will not be noticeable.

There is fog, and it is noticeable. And if the fog color change worked, then it would show up in properties anyway. But it didn’t.

maybe try Color3.new instead of Color3.fromRGB?

i think Color3.new would need a value between 0 and 1, or HSV or whatever you call it. I’m solely using RGB values so no.

my bad, although i noticed that maybe v.Name could be the problem here, maybe you could try using the index of the value instead of the name of the value (if it still doesn’t work then you could maybe try doing

local color1,color2,color3,color4 = table.unpack(colors)

game.Lighting.FogColor = Color3.fromRGB(color1)

and instead of having ["City"] = {255, 0, 0} you just have the rgb values like

local colors = {
   {255, 0, 0},
   {255, 0, 0},
   {255, 0, 0},
   {175, 206, 212}
}

also please excuse me if i start spouting out random nonsense, i’m pretty braindead today

I don’t know. v.Name worked for the skybox changing part perfectly fine, so I don’t see a reason why it wouldn’t in this case.

I gave each table of values it’s own name so the script can find it later.

i think roblox assumes that ["City"] = {225, 0, 0} is the entire value, instead of just {255, 0, 0}, and if you want to find it later you can just use color1, color2, etc. since we’re basically just trying to set the table to multiple variables, i guess you could try to check by doing a quick print(v.Name)

What?

That’s not how tables work.

local colors = { 
	["City"] = {255, 0, 0}
}

This would mean “City” equals to this table, {255, 0, 0}.

So whenever we run unpack(colors["City"]), it turns the table labelled “City” into individual values, which we can then use as Color3 values. I really don’t understand how any of what you just said helps my situation.

oops, sorry about that, i’m not well versed with sub-tables, pretty sure the only thing i did was give an overcomplicated example that does practically the same thing LOL, anyways if you’re unpacking the values for say, [“City”] then wouldn’t that just return the numbers? you might have to explicitly define which values would be red, green, and blue.
(also, i’m pretty sure the brackets and quotations are also unnecessary)

although still i might just be spouting nonsense here lol, trying my best to help out here :man_shrugging:

Nevermind, I got it to work by myself. Turns out it was none of these things.

1 Like

that’s good to know, sorry i couldn’t be of any help in your endeavor :confused: