So, in a game I'm making I have these different pads going into a tunnel with Touched scripts. How do I make it so that each pad going in turns your screen darker the deeper you go into it?
EDIT- This is the current script- What can I add to make the screen turn dark rather than the place? So that only the player that steps on a pad gets their screen blacked out?
function onTouched(Touch) game.Lighting.Ambient = Color3.new((240/255), (240/255), (240/255)) game.Lighting.Brightness = 0.98 end function Soundy(Part) game.Workspace.Sound.Pitch = .98 -- Changing pitch of the song that's playing ingame end script.Parent.Touched:connect(onTouched) script.Parent.Touched:connect(Soundy)
If you don't understand what I'm saying, just comment so, and I'll try to rephrase.
Well, the script you have right now would set the ambient for every player, but if that's what you're going for couldn't you just set the pads to change the ambient to darker colours/change the brightness to be lower?
Either way, I'd recommend using a Frame with BackgroundColor3 set to black anyway. You can set it for an individual player, and it can be as black as you please. You can use RemoteEvents to set the BackgroundTransparency of the Frame based on how deep in the tunnel you are:
In a server script:
game.Players.PlayerAdded:connect(function(olayer) local event = Instance.new("RemoteEvent", player) event.Name = "Screen" end)
In the sensors/pads:
function onTouched(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) local event = player:FindFirstChild("Screen") -- **EDIT:** My mistake, never got the actual player. local darkness = 0.1 -- Increase as pads increase, maximum of 1. event:FireClient(player, darkness) end function Soundy(Part) game.Workspace.Sound.Pitch = .98 end script.Parent.Touched:connect(onTouched) script.Parent.Touched:connect(Soundy)
In a LocalScript:
local player = game.Players.LocalPlayer local event = player:WaitForChild("Screen") local obscure = Instance.new("ScreenGui", player.PlayerGui) local frame = Instance.new("Frame", obscure) frame.BackgroundColor3 = Color3.new(0, 0, 0) frame.Transparency = 1 event.OnClientEvent:connect(function(brightness) frame.Transparency = brightness end)
That's sort of how I would do it (different typing it here), but I'm curious as to what you intend to do when the player exits the cave..
Hope this helped.
Assuming your script is a normal script, it will change Lighting's properties for every client as Pyrondon said. If you would still prefer the dimming, but want each player to have their own effects, instead of using a screen-sized frame that goes opaque after awhile, you can learn about Filtering Enabled
F.E. helps prevent exploiters and at the same time allows neat client-side effects like the client-side ambience dimming you're looking for. If you have F.E. enabled in "Workspace" then you can wrap your functions into Remote Events like so:
Touchy = Instance.new("RemoteEvent",game.ReplicatedStorage) Touchy.Name = "ClientDimmer" Soundy = Instance.new("RemoteEvent",game.ReplicatedStorage) Soundy.Name = "ClientSounder" Touchy.OnClientEvent:connect(function() game.Lighting.Ambient = Color3.new((240/255), (240/255), (240/255)) --You can remove the inner parenthesis per RGB value but it's okay to leave them there for preference. game.Lighting.Brightness = 0.98 --[[ If you plan on decreasing brightness in increments, do game.Lighting.Brightness = game.Lighting.Brightness - (WHATEVER INCREMENT) Careful though, directly copy pasting my code will let you rapidly drop brightness by touching the pad over and over. ]] end) Soundy.OnClientEvent:connect(function() game.Workspace.Sound.Pitch = .98 --Do you mean to play this sound or just change its pitch? end)
I would prefer to store the above code in a Script located in "ServerScriptService"
script.Parent.Touched:connect(function(hit) --You can use one event to call both functions! local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player == nil then return end game.ReplicatedStorage.ClientDimmer:FireClient(player) --Run touchy game.ReplicatedStorage.ClientSounder:FireClient(player) --Run soundy end)
^ And put that script inside the pad(s)
tl;dr I did it for you, dissect my script(s) so you can do it too!