Why won't this script work?

I am attempting to create a script where users with a certain rank in a group doesn’t have the fog but others do. Here is what I’ve come up with.

local Player = game:GetService("Players")

local Lighting = game:GetService("Lighting")

Player.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function()
		if plr:GetRankInGroup(5030945) >= 6 then
			game.ServerScriptService.Fog.Disabled = true
		end
		if plr:GetRankInGroup(5030945) <= 5 then
			game.ServerScriptService.Fog.Disabled = false
		end
	end)
end)

Both this script and the script called “Fog” is located in ServerScriptService. Any help would be appreciated of why this won’t work.

2 Likes

Is there two script with the same name Fog? If that’s true, then you must change the actual fog’s name into another different name because the script gets confused which one to disable, and since it got confused, it thinks the compiler should disable THIS script.

3 Likes

One script it named fog, and the script that I leaked in this topic is named “FogRanks.” So I don’t think that’s the issue.

1 Like

Which one is named FogRanks? This script?

1 Like

Yes, this one is named FogRanks.

1 Like

May I ask why wouldn’t you use the Lighting service’s fog children as the fog?

2 Likes

Not sure. Should I be doing this a different way?

1 Like

Disabling scripts on the server affects everyone, and depending on when the script runs, may do nothing at all in this case.

What you need to do is check each player’s rank, as you’re doing, and fire a RemoteEvent to just that player, with the information about whether or not they should see fog, then you receive the event in a LocalScript so that your changes to Lighting properties affect only their client.

4 Likes

That doesn’t require any script. It would automatically add a fog, you’ll have to adjust the properties though.

1 Like

If you put Post Processing Effects into game.Lighting, it shows for the whole server regardless if the group rank is in there. Put your PPE into workspace.Camera instead and see how it goes.

Of course, you’ll need to change game:GetService("Lighting") to workspace:FindFirstChild("Camera")