Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

im getting an error screen gui is not a valid member of playergui.Why?

this is the funtcion:

function ChangeText(Text)
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		Players[i].PlayerGui.Main.Time.Text = Text
	end
end

And i have a testing game and a like game with everythng built and there is nothing wrong in the testing but when i put it in the other game it doesnt work.If filtering enabled is on or of it doesnt work.Idk why.

######Edited 16:02 11/8/17 :: Format your code correctly

2 comments

0

Next time use the Lua icon to format your code correctly.

0

Can we make it clear? Your display is at your computer so you can see it, not ROBLOX's servers.

2 answers

The server is unable to access the PlayerGui under any circumstance, you should use RemoteEvents and RemoteFunctions to get past this, here is a wiki article that explain them.

The Server (which is the game) cannot access the Player's PlayerGui when Filtering Enabled is on or off (I don't really know about that, the off part.) So, I would advise you to use a LocalScript or a RemoteEvent or RemoteFunction to fully access a Player's PlayerGui

For a RemoteFunction, here is what it looks like using your function;

game.ReplicatedStorage.RemoteFunction.OnClientInvoke = function(text)
	local player = game.Players.LocalPlayer
	player.PlayerGui.Main.Time.Text = text
end

[Note]: Replace RemoteFunction to whatever you have named your RemoteFunction and replaced ReplicatedStorage to whatever was the RemoteFunction's parent is. Also, when using .OnClientInvoke, you do not need a Player argument because the LocalScript can get a Player by doing this; local player = game.Players.LocalPlayer

Now for the RemoteEvent;

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(text)
	local player = game.Players.LocalPlayer
	player.PlayerGui.Main.Time.Text = text
end)

[Note]: Same note from the RemoteFunction example, but this time, you will need to connect the event, OnClientEvent to make it work properly.

For more information; click here!

Hope this helped!

3 comments

0

Thx so much dude

0

wait nvm it worked only in studio

0

@JollyDumb you should add a :WaitForChild(ENTERNAME) to every parent, like player:WaitForChild("PlayerGui") and so on.

This discussion is preserved as it was. New answers, comments, and votes are closed.