Why the script is not working with the "Enabled"

Hi, im trying to do “Black Screen” effect.
And when i try to Enable and disable it after certain time the script does not work.
Why?

(also sorry for my spelling)
Have an awesome day! :wink:

1 Like

You do not want to use StarterGui. Everything in StarterGui gets replicated into their PlayerGui when they join. Instead, you want to use player.Playergui.

part.Touched:Connect(function(hit)
       local player = game.Players:GetPlayerFromCharacter(hit.Parent)
       if player then
            player.PlayerGui.ScreenGui2.Enabled = true
            wait(2
            player.PlayerGui.ScreenGui2.Enabled = false
      end
end

Hello!

The StarterGui GUI is not the GUI that is attached to the player.
You would need to do something like below instead:

Player.PlayerGui.ScreenGui2.Enabled = true

Replying also to @XdJackyboiiXd21

I tried this one

And also tried replacing it with yours @alphajpeg
Both still did not work :confused:

The code is correct (besides the true and false changing so I fixed that)

part.Touched:Connect(function(Hit)
	local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
	if Player then
		Player.PlayerGui.ScreenGui2.Enabled = true
		wait(2)
		Player.PlayerGui.ScreenGui2.Enabled = false
	end
end)
3 Likes

Yeah sorry, I forgot to make it set it to false after 5 seconds. I accidentally put true instead of false.

Thank you! It works now :sweat_smile:
Sorry for being so bad at scripting that you basically “had” to fix it for me…

Thank you @XdJackyboiiXd21 & @alphajpeg

1 Like