Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make fog only affect one person?

Asked by 4 years ago
Edited 4 years ago

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

0
Also, there are indents in my coding, not sure why they didn't want to appear PixelatedCube64 28 — 4y
0
Try copying this code in a LocalScript. LazokkYT 117 — 4y
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 PixelatedCube64 28 — 4y
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 greatneil80 2647 — 4y
0
Just for clarity, I have to move the LocalScript to somewhere besides the part they have to touch, right? PixelatedCube64 28 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

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.

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" Justingamer700 114 — 4y
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? PixelatedCube64 28 — 4y
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 Justingamer700 114 — 4y
1
hover* Justingamer700 114 — 4y
Ad

Answer this question