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

Gui shows up for one player at a time instead of all players at the SAME time? [Solved]

Asked by
Mayk728 855 Moderation Voter
7 years ago
Edited by OldPalHappy 7 years ago

I have a script that would show each player a message after a certain time. After the message appears, some code is run. The more players i have in game, the longer it takes. I tested on studio to see what happens with 2 players and i saw that the Gui shows up for one player at a time. I want it to show for all players at the SAME time. Anyone know what i need to do to fix this?

function Message()
    for i,v in pairs(game.Players:GetPlayers()) do
        local msg = v:WaitForChild("PlayerGui").ScreenGui.Message
        message.Visible = true
        wait(3)
        message.Visible = false
    end
end

while true do
    wait(20)
    Message()
    --Code to run
end

Also, this is a normal ServerScript in Workspace.

Any help would be appreciated!

1 answer

Log in to vote
2
Answered by 7 years ago
Edited 7 years ago

It's because of the wait in the loop inside the function.

I recommend simply using spawn inside the message function, like so:

function Message()
    for i,v in pairs(game.Players:GetPlayers()) do
        spawn(function()
            --I changed this part to msg instead of message. You might not want this.
            local msg = v:WaitForChild("PlayerGui").ScreenGui.Message
            msg.Visible = true
            wait(3)
            msg.Visible = false
        end)
    end
end

while true do
    wait(20)
    Message()
    --Code to run
end

EDIT:

Scripts running on the server can't access GUIs from the players' playerGui that they did not create and add there, meaning it won't see the ScreenGui, or the Message.

You'll have to use Remote Events.

--// Regular Script

local remoteEvent = game.ReplicatedStorage.REMOTEEVENTNAME

while true do
    wait(20)
    remoteEvent:FireAllClients()
end

--// Local Script on the client; like in PlayerGui.

local remoteEvent = game.ReplicatedStorage.REMOTEEVENTNAME
local gui = DEFINE GUI

remoteEvent.OnClientEvent:Connect(function()
    gui.Visible = true
    wait(3)
    gui.Visible = false
end)
0
This doesn't seem to be working for me. When i test with 2 players on studio, nothing happens. When i test in game with 2 players, I get an error saying ScreenGui is not a valid member of PlayerGui. I tried changing it to :WaitForChild("ScreenGui") but it gives me infinite yield possible. Mayk728 855 — 7y
0
Yup. Let me edit this. OldPalHappy 1477 — 7y
0
How exactly do i use the RemoteEvent to access the players Gui? I haven't used this before so i'm not so familiar with it. Mayk728 855 — 7y
0
You just put a RemoteEvents in replicated storage and follow the tutorial. There are many tutorials out there to help you understand remote events, but basically they're like a portal, or connection, that lets the Server interact directly with the Client. OldPalHappy 1477 — 7y
View all comments (7 more)
0
All you said was to put the remoteEvent inside of replicated storage and then use :FireAllClients() but it doesn't look like it's interacting with the Gui's? Mayk728 855 — 7y
0
FireAllClients() sends a signal to all the clients, signals which the LocalScripts inside the clients can pick up on, and then they can do whatever they want with the information the signal gives. OldPalHappy 1477 — 7y
0
So you need both a Regular Script and a Local Script for this process to work. OldPalHappy 1477 — 7y
0
Okay so i just found out that FilteringEnabled was ENABLED. I disabled it and now the script works without the remoteEvents thing you said. Mayk728 855 — 7y
0
If you're still confused, I recommend watching this: https://www.youtube.com/watch?v=4Dc_bri9mjs OldPalHappy 1477 — 7y
0
Okay, thank you. Mayk728 855 — 7y
0
Well, without Filtering, you're game won't show for people under 13, and the game is super vulnerable to exploits. OldPalHappy 1477 — 7y
Ad

Answer this question