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

Black screen won't go away, even when the GUI is destroyed?

Asked by 6 years ago

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:

local function darknessCycle()
    local darknessClone = game.ServerStorage.Darkness:Clone()
    darknessClone.Name = ("darknessClone")
    darknessClone.Parent = game.StarterGui
    local darknessTimer = 0
    math.randomseed(tick())
    wait(0.5)
    local darknessTime = math.random(2,10)
        for _ = 1, darknessTime, 1 do
        darknessTimer = darknessTimer + 1
        wait(1)
        print(darknessTime)
        print(darknessTimer)
    end
    print ("darknessTimer finished")
    darknessClone:Destroy() -- ??????
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?

0
By the way, I am aware that the function hasn't been called. When it is, it won't work. DaBrainlessOne 129 — 6y

1 answer

Log in to vote
1
Answered by
awfulszn 394 Moderation Voter
6 years ago
Edited 6 years ago

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:

for _, v in pairs(game.Players:GetPlayers()) do
    v.PlayerGui.darknessClone:Destroy()
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.

for _, v in pairs(game.Players:GetPlayers()) do
    if v.PlayerGui.darknessClone ~= nil then
      v.PlayerGui.darknessClone:Destroy()
    else
      print('123')
    end
end
0
Yeah, that works. Just making an example, though. awfulszn 394 — 6y
Ad

Answer this question