[SOLVED] Comprehension on PlayerGui through a Script Function

ISSUE: I am trying to Parent PlayerGui in Workspace > Script which calls an Event function, for when the Event occurs the TextLabel > ScreenGui will be shown for all clients. However, for some reason I cannot find a way to Parent PlayerGui in the Script, any idea on how I can achieve this…?

SCRIPT:

-- PowerOutage Script
-- Parent the PlayerGui
local Lighting = game:GetService("Lighting") -- The instance is from Lighting.
local PowerBox = workspace["Handler (W)"].Map.KillArea.PowerOutage.PowerBox
local LightPart = workspace["Handler (W)"].AI.Monster.AIMain.Settings.JumpscareSettings.CameraPart
local Sounds = workspace["Handler (W)"].Map.KillArea.PowerOutage.PowerBox.PowerSounds -- Recognising the Group of Sounds.
local BackgroundSounds = workspace["Handler (W)"].BackgroundSounds
local Button = workspace["Handler (W)"].Map.KillArea.PowerOutage.PowerBox.Button
-- local PowerOutageGui = -- Parent the PlayerGui
local OnSound = Sounds:WaitForChild("PowerOn")
local OffSound = Sounds:WaitForChild("PowerOff")
-- local ChargeSound = Part:WaitForChild("ChargeSound")

local ProximityPrompt = Button:WaitForChild("ProximityPrompt")

local Cooldown = false
local Duration = 55 -- Duration in Seconds.

local PowerState = "On"

-- Getting the List of Lights
local LightList = {}
for _, Lights in pairs(workspace["Handler (W)"].Map.KillArea.Lights:GetDescendants()) do
	if Lights:IsA("Model") and Lights.Name == "LightBulb" then
		table.insert(LightList,Lights)
	end
end


-- Helper Functions
function SetPowerOn()
	for _, Lights in pairs(LightList) do -- Pairing as an instance.
		Lights.Bulb.PointLight.Brightness = 1 -- Making the "Lights" Brightness 1 (On).
		Lights.Bulb.PointLight.Enabled = true
		Lights.Light.Transparency = 0 -- Simply making it that the Neon Part is Transparent.
	end
	BackgroundSounds.Ambience:Play() -- BackgroundSound Sound will (Start).
	Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
	Lighting.Atmosphere.Haze = 0 -- Same Here.
	LightPart.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
	PowerBox.Highlight.Enabled = false
	PowerBox.Button.ProximityPrompt.Enabled = false
	PowerBox.Button.Color = Color3.new(0, 161, 0)
	-- PowerOutageGui.Visible = false -- Calling the TextLable in PlayerGui

	PowerState = "On"
end

function SetPowerOut()
	for _, Lights in pairs(LightList) do -- Pairing as an instance.
	    Lights.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off).
		Lights.Bulb.PointLight.Enabled = false
		Lights.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent.
	end
	BackgroundSounds.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
	Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
	Lighting.Atmosphere.Haze = 10 -- Same Here.
	LightPart.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
	PowerBox.Highlight.Enabled = true
	PowerBox.Button.ProximityPrompt.Enabled = true
	PowerBox.Button.Color = Color3.new(0, 0, 0)
	-- PowerOutageGui.Visible = true -- Calling the TextLable in PlayerGui
	
	PowerState = "Off"
end

ProximityPrompt.Triggered:Connect(function()
	-- ChargeSound:Play()
	OnSound:Play()
	OffSound:Stop()
	SetPowerOn()
end)

SetPowerOn()

while true do 
	task.wait(Duration)
	OffSound:Play()
	OnSound:Stop()
	SetPowerOut()
	while (PowerState == "Off") do
		task.wait()
	end
end

Why not just use a serverscript and do :GetPlayers() in a for loop
(i.e, for _, player in pairs(game:GetService"Players"):GetPlayers()) )
Then after that, get the v’s (which is the player) PlayerGui, then use :FindFirstChild() or :WaitForChild() to get the specific ScreenGui containing the TextLabel then set the TextLabel’s visibility to true

2 Likes

Did you see where I placed the notes for where the line Script is spose to occur?

and can the Script not work in Workspace? Just curious.

Only localscripts cannot work in workspace but server scripts can. And yes I saw the notes.

Okay thank you! And so how would I make this part of the Script…?

Maybe something like this then put it under the functions

for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
	if Player:FindFirstChildOfClass("PlayerGui") then
		local AnyVariableHere = Player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("Your gui name here that contains the TextLabel.")
		
		if AnyVariableHere ~= nil then
			AnyVariableHere.Path_Of_TexLabel.Visible = true
		end
	end
end
1 Like

There’s another problem. The expectations are the TextLabel will show when the Power goes out, but I cannot Parent the TextLabel.

If you’re trying parent the textlabel outside of the screengui, the textlabel will not show as a result. Why not just edit the properties needed excluding the Parent? But if you do want to Parent the textlabel outside of the screengui, how come .Parent = ExampleHere doesn’t work?

1 Like

Is this a good way to represent the Parent –

local Sounds = game.ReplicatedStorage["Handler (RS)"].Sounds:WaitForChild("PowerSounds") -- Recognising the Group of Sounds.

Yes. Any style of representing an instance as long it is efficient and correct, it’s a good way.

1 Like

Where you see -- PowerOutageGui.Visible = true-- Calling the TextLable in PlayerGui this is where to TextLabel will be shown.

-- Helper Functions
function SetPowerOut()
	for _, Lights in pairs(LightList) do -- Pairing as an instance.
	    Lights.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off).
		Lights.Bulb.PointLight.Enabled = false
		Lights.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent.
	end
	BackgroundSounds.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
	Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
	Lighting.Atmosphere.Haze = 10 -- Same Here.
	LightPart.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
	PowerBox.Highlight.Enabled = true
	PowerBox.Button.ProximityPrompt.Enabled = true
	PowerBox.Button.Color = Color3.new(0, 0, 0)
	-- PowerOutageGui.Visible = true -- Calling the TextLable in PlayerGui
	
	PowerState = "Off"
end
for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
	if Player:FindFirstChildOfClass("PlayerGui") then
		local PowerOutageGui = Player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("PowerOutageGui")

		if PowerOutageGui ~= nil then
			PowerOutageGui.TextLabel.Visible = true
		end
	end
end
1 Like

When the Power turns (Off), the TextLabel in PowerOutageGui will show. Then it will fade away, so it isn’t permanent for when the Power is (Off). When the Power is turned (On) the TextLabel doesn’t show at all. This process will repeat forever until the Player leaves the game.

The TextLabel will say “Find the Power Box to activate the Power.”

1 Like

@yesimrealll

Max character limit

Are you sure you typed in the correct path of the textlabel? Is there something else in the script turning the visibility of the textlabel to false once the power is on? Or is it intentional that it won’t show when the power is on?

1 Like

The PowerOutageGui is a ScreenGui parted way in StarterGui.

@yesimrealll

-- PowerOutage Script
local Lighting = game:GetService("Lighting") -- The instance is from Lighting.
local PowerBox = workspace["Handler (W)"].Map.KillArea.PowerOutage.PowerBox
local LightPart = workspace["Handler (W)"].AI.Monster.AIMain.Settings.JumpscareSettings.CameraPart
local Sounds = game.ReplicatedStorage["Handler (RS)"].Sounds:WaitForChild("PowerSounds") -- Recognising the Group of Sounds.
local BackgroundSounds = workspace["Handler (W)"].BackgroundSounds
local Button = workspace["Handler (W)"].Map.KillArea.PowerOutage.PowerBox.Button
local OnSound = Sounds:WaitForChild("PowerOn")
local OffSound = Sounds:WaitForChild("PowerOff")
-- local ChargeSound = Part:WaitForChild("ChargeSound")

local ProximityPrompt = Button:WaitForChild("ProximityPrompt")

local Cooldown = false
local Duration = 55 -- Duration in Seconds.

local PowerState = "On"

-- Getting the List of Lights
local LightList = {}
for _, Lights in pairs(workspace["Handler (W)"].Map.KillArea.Lights:GetDescendants()) do
	if Lights:IsA("Model") and Lights.Name == "LightBulb" then
		table.insert(LightList,Lights)
	end
end

for _, Player in pairs(game:GetService("Players"):GetPlayers()) do
	if Player:FindFirstChildOfClass("PlayerGui") then
		local PowerOutageGui = Player:FindFirstChildOfClass("PlayerGui"):FindFirstChild("PowerOutageGui")

		if PowerOutageGui ~= nil then
			PowerOutageGui.TextLabel = false
		end
	end
end


-- Helper Functions
function SetPowerOn()
	for _, Lights in pairs(LightList) do -- Pairing as an instance.
		Lights.Bulb.PointLight.Brightness = 1 -- Making the "Lights" Brightness 1 (On).
		Lights.Bulb.PointLight.Enabled = true
		Lights.Light.Transparency = 0 -- Simply making it that the Neon Part is Transparent.
	end
	BackgroundSounds.Ambience:Play() -- BackgroundSound Sound will (Start).
	Lighting.Atmosphere.Density = 0 -- Disabling the Fog pressure level.
	Lighting.Atmosphere.Haze = 0 -- Same Here.
	LightPart.PointLight.Enabled = false -- Making the Monsters Torso has Non-translucent PointLight when "PowerOutage" is inactive.
	PowerBox.Highlight.Enabled = false
	PowerBox.Button.ProximityPrompt.Enabled = false
	PowerBox.Button.Color = Color3.new(0, 161, 0)
	-- PowerOutageGui.Visible = false -- Calling the TextLable in PlayerGui

	PowerState = "On"
end

function SetPowerOut()
	for _, Lights in pairs(LightList) do -- Pairing as an instance.
	    Lights.Bulb.PointLight.Brightness = 0 -- Making the "Lights" Brightness zero (Off).
		Lights.Bulb.PointLight.Enabled = false
		Lights.Light.Transparency = 1 -- Simply making it that the Neon Part is Transparent.
	end
	BackgroundSounds.Ambience:Stop() -- BackgroundSound Sound will (Stop) Playing.
	Lighting.Atmosphere.Density = 1 -- Creating the Fog pressure level.
	Lighting.Atmosphere.Haze = 10 -- Same Here.
	LightPart.PointLight.Enabled = true -- Making the Monsters Torso has translucent PointLight when "PowerOutage" is active.
	PowerBox.Highlight.Enabled = true
	PowerBox.Button.ProximityPrompt.Enabled = true
	PowerBox.Button.Color = Color3.new(0, 0, 0)
	-- PowerOutageGui.Visible = true -- Calling the TextLable in PlayerGui
	
	PowerState = "Off"
end

ProximityPrompt.Triggered:Connect(function()
	-- ChargeSound:Play()
	OnSound:Play()
	OffSound:Stop()
	SetPowerOn()
end)

SetPowerOn()

while true do 
	task.wait(Duration)
	OffSound:Play()
	OnSound:Stop()
	SetPowerOut()
	while (PowerState == "Off") do
		task.wait()
	end
end

.TextLabel = false
Did you forget to type .Visible? If you want the textlabel to show once the power is on again why not put another one in the function that sets the power to on. Does this fix your issue?

1 Like