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

How do you darken a player's screen?

Asked by 8 years ago

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.

2 answers

Log in to vote
0
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
8 years ago

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.

0
I'm getting an error with your script for the pads at line 4. https://gyazo.com/69c10df5ec6332dbc350457ae8193393 jasonr95 5 — 8y
0
There's no errors or exceptions, but it doesn't actually make the player's screen darker. Am I placing something in the wrong place? Thank you for helping. jasonr95 5 — 8y
0
Well, I figured you'd know you have to set the frame's size to fill the entire screen: frame.Size = UDim2.new(1, 0, 1, 0). Pyrondon 2089 — 8y
0
I've never dealt with frames before, I'm also not very experienced in general. Can you explain more, if you don't mind, please? jasonr95 5 — 8y
0
nvm got it to work jasonr95 5 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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!

0
Rather than dimming, do you know how to get the screen to black out? jasonr95 5 — 8y
0
Thank you for helping! If I could upvote you guys I would :P jasonr95 5 — 8y
0
Like in Pyrodon's method, instead of setting a brightness like in mine, you can change it to adjust a GUI's 'BackgroundTransparency' value (0 is opaque, 1 is invisible) to black out the screen. Where you see 'game.Lighting.Brightness' and so forth, change the line(s) to adjust the aforementioned GUI of which should preferably be a 'Frame' with size UDim2.new(1,0,1,0).  Oh, you'll also have to loca Dynamese 35 — 8y
0
I think your comment is unfinished. jasonr95 5 — 8y
0
...also have to locate the Player you're dimming, but every time a client event is fired in the second script, it'll transfer the player object through.  If you stick some variable between the parenthesis of the functions of the first script, that variable will be assigned the Player that touched the button. Dynamese 35 — 8y

Answer this question