Can't acces PlayerGui for some reason

Hello,

So as you can see in the title I can’t acces the PlayerGui with an server-script I know its possible and I know I did that sometime but that was a very, very long time ago.

So it would be really helpfull if someone told me how I can acces the PlayerGui again.

Here’s the script in case you need it;

wait(5)

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local PlayerGui = player:WaitForChild("PlayerGui")

local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam"}

local companyNAMES = {"ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly" }
local ReplicatedStorage = game.ReplicatedStorage.RemoteFunctions.AbortFunctions.Order1.Order1Function


local tvOrdersRMD = {"OldTv", "Salora 58UA330"}


local randomtask = names[math.random(#companyNAMES)] -- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
local randomtask2 = math.random(#names)


local guiPlaces = game.StarterGui.ComputerMenu.Orders.Background1.OrderPlaces

if guiPlaces.Value == 0 then
	wait(5)
	
	local index
	
	index = math.random(1, #names)
	
	local i
	i = math.random(1, #tvOrdersRMD)
	
	local ORDER = Instance.new("TextButton")
	ORDER.Parent = PlayerGui.ComputerMenu.Orders.Background1
	ORDER.Size = UDim2.new(0.25, 0, 0.278, 0)
	ORDER.Position = UDim2.new(0.122, 0, 0.146, 0)
	ORDER.Name = "Order1"
	ORDER.BackgroundColor3 = Color3.fromHSV(0.54425, 0.886275, 1)
	ORDER.Text = "Name: ".. names[index]
	ORDER.TextSize = 20
	ORDER.LineHeight = 5
	
	local CircleGui = Instance.new("UICorner")
	CircleGui.Parent = ORDER
	
	local TvRMD = Instance.new("TextLabel")
	TvRMD.Name = "TVSelecter"
	TvRMD.Parent = ORDER
	TvRMD.Size = UDim2.new(1, 0, 0.301, 0)
	TvRMD.Position = UDim2.new(0, 0, 0.457, 0)
	TvRMD.BackgroundTransparency = 1
	TvRMD.TextSize = 18
	TvRMD.Text = "Order: ".. tvOrdersRMD[i]
	
	
	local ABORT = game.StarterGui.ComputerMenu.Orders.Background1.Abort:Clone()
	ABORT.Name = "AbortClone"
	ABORT.Parent = ORDER
	ABORT.Size = UDim2.new(0.25, 0, 0.278, 0)
	ABORT.Position = UDim2.new(0.85, 0, -0.1, 0)
	
	guiPlaces.Value = guiPlaces.Value + 1
	script.Disabled = true
	wait(5)
	script.Disabled = false
end


You can’t get local player through a server script.

Right, totally forgot that lol lets see if I can do something with that.

Try using remoteevents when handling the guis.

I changed the script to this;

wait(5)

local Players = game:GetService("Players")

local function onPlayerAdded(player)
	print(Players)
end

Players.PlayerAdded:Connect(onPlayerAdded)


local names = {"Monica", "Joey", "Sarah", "Phoebe", "Michel", "Michael", "James", "Adam"}

local companyNAMES = {"ElectroShop", "Cablebar" ,"Airedable" ,"Tv.Inc", "Videosify", "Tellyware", "Onaired", "Remixus", "Technomax", "Elevatelly", "Envideos", "Inc.ia", "Cotv", "Coremix", "Edaired", "Unitelly" }
local ReplicatedStorage = game.ReplicatedStorage.RemoteFunctions.AbortFunctions.Order1.Order1Function


local tvOrdersRMD = {"OldTv", "Salora 58UA330"}


local randomtask = names[math.random(#companyNAMES)] -- The 1st parameter defaults to 1 if it's not specified, so in this case we can just put #companyNAMES to find the max number in the table.
local randomtask2 = math.random(#names)


local guiPlaces = game.StarterGui.ComputerMenu.Orders.Background1.OrderPlaces

if guiPlaces.Value == 0 then
	wait(5)
	
	local index
	
	index = math.random(1, #names)
	
	local i
	i = math.random(1, #tvOrdersRMD)
	
	local ORDER = Instance.new("TextButton")
	ORDER.Parent = player.PlayerGui.ComputerMenu.Orders.Background1
	ORDER.Size = UDim2.new(0.25, 0, 0.278, 0)
	ORDER.Position = UDim2.new(0.122, 0, 0.146, 0)
	ORDER.Name = "Order1"
	ORDER.BackgroundColor3 = Color3.fromHSV(0.54425, 0.886275, 1)
	ORDER.Text = "Name: ".. names[index]
	ORDER.TextSize = 20
	ORDER.LineHeight = 5
	
	local CircleGui = Instance.new("UICorner")
	CircleGui.Parent = ORDER
	
	local TvRMD = Instance.new("TextLabel")
	TvRMD.Name = "TVSelecter"
	TvRMD.Parent = ORDER
	TvRMD.Size = UDim2.new(1, 0, 0.301, 0)
	TvRMD.Position = UDim2.new(0, 0, 0.457, 0)
	TvRMD.BackgroundTransparency = 1
	TvRMD.TextSize = 18
	TvRMD.Text = "Order: ".. tvOrdersRMD[i]
	
	
	local ABORT = game.StarterGui.ComputerMenu.Orders.Background1.Abort:Clone()
	ABORT.Name = "AbortClone"
	ABORT.Parent = ORDER
	ABORT.Size = UDim2.new(0.25, 0, 0.278, 0)
	ABORT.Position = UDim2.new(0.85, 0, -0.1, 0)
	
	guiPlaces.Value = guiPlaces.Value + 1
	script.Disabled = true
	wait(5)
	script.Disabled = false
end

And i’m getting this error;

Yes, but you cannot access the playergui from the server script, please use remote events when doing such tasks in your scripts.

I don’t think thats possible cause this script is in serverscriptservice and if I want to acces it with remote events/functions then that script needs to be somewhere in the chosen Gui. But… that gui is created with instance.new as you can see.

Please read the API reference:

You should do research on this.

1 Like

I already have read that page cause and I also know how I can use remote functions/events.

And I just found an script in my old game and there are no remote functions/events in the script even tho I still can acces the PlayerGui and that script is too in serverscriptservice so what u are saying is not really true. I mean sure its very helpfull to use remote functions/events and you are right about that, but sometimes you can just use other stuff to acces the PlayerGui.

Anyways thank you for your time!! But ima copy the script in my other game.