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

How do I access everyones playergui inside a server script?

Asked by 5 years ago

So this first script is a LOCAL SCRIPT This LOCAL SCRIPT is inside a TEXTBUTTON where only certain people can see.

script.Parent.MouseButton1Click:Connect(function(plr)
    game.ReplicatedStorage.DisableBalls:FireServer(game.Players:GetPlayers())
end)

The other script is a SERVER SCRIPT And this is inside SERVER SCRIPT SERVICE This is wrong i know that but I just want to know how do i access everyones playergui inside a server script?

game.ReplicatedStorage.DisableBalls.OnServerEvent:Connect(function(player, localplayer)
    for _,v in pairs(localplayer) do
        v.PlayerGui:WaitForChild("ScreenGui").Spawn.TextButton.Text = "Disabled"
        v.PlayerGui.ScreenGui.Spawn.TextButton.LocalScript.Disabled = true
    end
end)

This was just me having a go at it

0
No, ew, why would you do that? User#19524 175 — 5y
0
soz im not good at scripting WillBe_Stoped 71 — 5y
0
im just trying to make something where if you click a textbutton it should disable a script for everyone else WillBe_Stoped 71 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

to remove a gui on all clients, you could make a local script that fires to a server script which fires to a local script to remove the gui like this:

local script for textbutton

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer()
end)

server script

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
    game.ReplicatedStorage.RemoteEvent2:FireAllClients()
end)

local script for removing gui

local players = game.Players:GetPlayers()

game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Connect(function()
    for i,v in pairs(players) do
        v.PlayerGui.Thing:Destroy()
    end
end)

i keep on thinking i dont need to use the for i,v in pairs() do, bc i used :FireAllClients(), but it worked for him on discord so idc lol

Ad
Log in to vote
0
Answered by
Troxure 87
5 years ago
for i,plr in next, game:GetService("Players"):GetPlayers() do
local gui=plr:FindFirstChild("PlayerGui");
if(gui) then
--code here
print(plr.Name.." gui exists!");
end
end

Hope this helps!

0
servver script right? WillBe_Stoped 71 — 5y
0
Yes, as localscripts can only access your own playergui. Troxure 87 — 5y
0
sadly, it only worked in "play solo" mode but didn't work in Normal game WillBe_Stoped 71 — 5y
0
It must be in a script, not a localscript. Troxure 87 — 5y
View all comments (6 more)
0
it is a script WillBe_Stoped 71 — 5y
0
Are you trying to access Localplayer in the script? Troxure 87 — 5y
0
no everyone WillBe_Stoped 71 — 5y
0
But do you try to define LocalPlayer anywhere within the script because you can only access LocalPlayer through a localscript, and if youre trying to access it through the script, it could be breaking your script causing your issue... Troxure 87 — 5y
0
Ok lemme put it this way. When the event is fired i want the server script to access everyone elses playergui and disable a textbutton WillBe_Stoped 71 — 5y
0
I don't just want the LOCALPLAYER's TextButton thing to be disabled. I want everyone elses WillBe_Stoped 71 — 5y

Answer this question