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

Why is the FogEnd not changing?

I'm new to scripting and I need help with this fog script.

What this script is supposed to do is when the player is touching the part the fog will be less dense to its default. (300)

But when the player stops standing on the part the fog will become denser. (50)

The problem is that this script is doing nothing and not changing the FogEnd value. I see no errors on the output. (This is on a local script)

Any fix?

Fog = script.Parent

local function onTouch(otherPart)
	local character = otherPart.Parent
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		Fog.Touched:Connect(onTouch)
		game.Lighting.FogEnd = ("300")
		
		Fog.TouchEnded:Connect(onTouch)
		game.Lighting.FogEnd = ("50")
	end
end


Also, how I make where the fog will transition between the values that way the fog won't be changed in an instant.

would I add

for i=1,10 do...

?

3 comments

0

look at where you are establishing your functions

0

what fogEnd?

0

You never call the function, and that's not how you connect to events either

1 answer

You're problems is that:

  1. the touching event is inside of the function in which it's invoking, meaning it will never actually get to the function

  2. you're using the "Touched" and "TouchEnded" events, which are extremely unstable.

  3. "FogEnd" is a number value, and you're putting in a string value (will still work though)

This is a script I wrote that will use "FindPartsInRegion3", meaning it will find any part that is touching (or inside) the fog. The only downside is that it isn't very efficient, so it may lag the server a bit because of the while loop (but you should be using this on the client anyway).

Fog = game.Workspace.Fog --Wherever your fog is
local region = Region3.new(Fog.Position-(0.5*Fog.Size), Fog.Position+(0.5*Fog.Size))
while wait() do
	local parts = workspace:FindPartsInRegion3(region, Fog) --Finding all parts that are inside of fog
	for i,v in pairs(parts) do
		if v.Parent == game.Players.LocalPlayer.Character then --Checking if the object touching inside is the player
			game.Lighting.FogEnd = 50
			break -- Stopping the function just in case a non-humanoid object is inside of the part
		elseif i == #parts then --Making sure that it is at the end of all parts before setting fog back to normal
			game.Lighting.FogEnd = 300
		end
	end
end

One thing about your script:

It will turn the current client's fog "foggy" even if another client is inside the fog.

Note: put this script inside of a localScript inside of StarterPlayerScripts (or starterGui) for it to function.

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