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

My "for i,v in pairs(Game.players:GetPlayers()) do " is doing error with gui ?

Asked by 5 years ago
Edited 5 years ago

So when i try to show a gui like this . in a script in the ServerScriptService

while true do
    wait(10)
    for i,v in pairs(game.Players:GetPlayers()) do
        v.PlayerGui.GUI.Block.Visible = true
    end
end

and after this . it show me this in the output !

17:21:51.288 - GUI is not a valid member of PlayerGui

and by the way the gui is in the playerGui !

0
PlayerGui's descendants are not accessible by server scripts, you have to use a local script to access it aazkao 787 — 5y
0
Just a side note, it seems you're making this an infinite loop, but after it becomes visible you don't exactly need to make it visible again every 10 seconds unless something else is making it invisible repeatedly... vanilla_wizard 336 — 5y

1 answer

Log in to vote
0
Answered by
popeeyy 493 Moderation Voter
5 years ago

You cannot access PlayerGui from ServerScriptService. Here is what you should do instead:

Create a "RemoteEvent" inside of ReplicatedStorage and name it "blockEvent"

You should have a server script with this code:

while wait(10) do --Every 10 seconds
    game:GetService('ReplicatedStorage'):WaitForChild('blockEvent'):FireAllClients() --Fires everyone's client to set the visiblility to true.
end

You should have a local script inside StarterGui with this code:

game:GetService('ReplicatedStorage'):WaitForChild('blockEvent').OnClientEvent:connect(function() -- When the client is fired from that player.
    script.Parent.GUI.Block.Visible = true --Set the visibility to true.
end)

Hope this helps! If you need further help, just comment.

Ad

Answer this question