I'm trying to make a script (and I'm fairly new to this) that when run, would make a black screen, wait a while, then take the screen away.
Here it is:
01 | local function darknessCycle() |
02 | local darknessClone = game.ServerStorage.Darkness:Clone() |
03 | darknessClone.Name = ( "darknessClone" ) |
04 | darknessClone.Parent = game.StarterGui |
05 | local darknessTimer = 0 |
06 | math.randomseed(tick()) |
07 | wait( 0.5 ) |
08 | local darknessTime = math.random( 2 , 10 ) |
09 | for _ = 1 , darknessTime, 1 do |
10 | darknessTimer = darknessTimer + 1 |
11 | wait( 1 ) |
12 | print (darknessTime) |
13 | print (darknessTimer) |
14 | end |
15 | print ( "darknessTimer finished" ) |
16 | darknessClone:Destroy() -- ?????? |
17 | end |
The thing is, when the script is run, and the darknessClone is destroyed, the black screen still stays. Is there something I'm missing that I need to get rid of it?
It's because you're cloning the Gui to the StarterGui
, which is cloned to the PlayerGui
when a player joins. If you want the black screen destroyed, :Destroy()
the Gui from thePlayerGui
.
Example:
1 | for _, v in pairs (game.Players:GetPlayers()) do |
2 | v.PlayerGui.darknessClone:Destroy() |
3 | end |
Note: You may want to check if the GUI is there before removing it, just a precaution, so it won't error.
Replace line 16 with this.
1 | for _, v in pairs (game.Players:GetPlayers()) do |
2 | if v.PlayerGui.darknessClone ~ = nil then |
3 | v.PlayerGui.darknessClone:Destroy() |
4 | else |
5 | print ( '123' ) |
6 | end |
7 | end |