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

How do I make fog only affect one person?

So, I've been making a game where the fog changes after you go through an invisible part. here's what I got so far

function onTouched(hit) game.Lighting.FogColor = Color3.new(0, 0, 0) game.Lighting.FogEnd = 100 end script.Parent.Touched:connect(onTouched)

Is there a way to make it so this only affects players who touch the block? If it helps, you can't exit the area with this code :) Thanks

5 comments

0

Also, there are indents in my coding, not sure why they didn't want to appear

0

Try copying this code in a LocalScript.

0

Assuming you're answering my question and not giving me a solution to fixing my script indents here, I tried replacing the script with a LocalScript, and it just didn't work. Sorry

0

it should work if you move it to a localscript, if it doesn't then the only thing I see is that you left the script.Parent in the localscript and the parent is no longer the touchpad

0

Just for clarity, I have to move the LocalScript to somewhere besides the part they have to touch, right?

1 answer

✓ Accepted answer

Alright so you're gonna have to insert a remote into ReplicatedStorage. Name the remote event "CreateFog".

Insert a Script into the part you want to be touched to create the fog and paste the following script into the Script

local Touched 

Touched = script.Parent.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("HumanoidRootPart") then return end
	local target = hit.Parent
	game.ReplicatedStorage.CreateFog:FireClient(game.Players:GetPlayerFromCharacter(target))
end)

After you're finished with the script, insert a LocalScript into StarterPlayerScripts and paste the following script into the LocalScript

game.ReplicatedStorage.CreateFog.OnClientEvent:Connect(function()
	local Lighting = game:GetService("Lighting")
	Lighting.FogColor = Color3.new(0, 0, 0)
	Lighting.FogEnd = 100
end)

This was tested and it works.

4 comments

0

Just in case you don't know, to view the full script, hover your mouse over one of the lines and on the top right corner of it, click "view source"

0

Thanks for the very easy directions, it worked perfectly! Also, if you don't mind me asking, how exactly did you create the view scorce thing?

1

I didn't make it. When you press the LUA logo when typing your question/answer and pasteyour script in between the lines that pop up, people can hoer their mouse over it and press view source

1

hover*

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