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

How do I access everyones playergui inside a server script?

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

3 comments

0

No, ew, why would you do that?

0

soz im not good at scripting

0

im just trying to make something where if you click a textbutton it should disable a script for everyone else

2 answers

✓ Accepted answer

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

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!

10 comments

0

servver script right?

0

Yes, as localscripts can only access your own playergui.

0

sadly, it only worked in "play solo" mode but didn't work in Normal game

0

It must be in a script, not a localscript.

0

it is a script

0

Are you trying to access Localplayer in the script?

0

no everyone

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...

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

0

I don't just want the LOCALPLAYER's TextButton thing to be disabled. I want everyone elses

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