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
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
1 | local Touched |
2 |
3 | Touched = script.Parent.Touched:Connect( function (hit) |
4 | if not hit.Parent:FindFirstChild( "HumanoidRootPart" ) then return end |
5 | local target = hit.Parent |
6 | game.ReplicatedStorage.CreateFog:FireClient(game.Players:GetPlayerFromCharacter(target)) |
7 | end ) |
After you're finished with the script, insert a LocalScript into StarterPlayerScripts and paste the following script into the LocalScript
1 | game.ReplicatedStorage.CreateFog.OnClientEvent:Connect( function () |
2 | local Lighting = game:GetService( "Lighting" ) |
3 | Lighting.FogColor = Color 3. new( 0 , 0 , 0 ) |
4 | Lighting.FogEnd = 100 |
5 | end ) |
This was tested and it works.