Hey, how do you create a script that changes all Player GUIs at once in a server? I have tried, but I am only a basic scripter and don't know much at all.
1 | local playerss = game.Players:GetChildren() |
2 | local m = playerss.titel.fram.label |
3 |
4 | while true do |
5 | m.Text = "Testing" |
6 | end |
That's the code I made up, and it doesn't work. Does anyone know how to make scripts that change Player guis?
Hey there Dylan!
So, your playerss
variable is a table that was passed in by GetChildren()
, and you therefore need to loop through it, like so:
01 | local playerss = game.Players:GetPlayers() -- Just in case there are children that aren't players |
02 | while true do |
03 | for i, v in pairs (playerss) do -- loop through players |
04 | local m; |
05 | local playergui = playerss:findFirstChild( "PlayerGui" ); -- UI is found in the PlayerGui |
06 | if (playergui and playergui:findFirstChild( "titel" )) then |
07 | if (playergui.titel:findFirstChild( "fram" )) then |
08 | if (playergui.titel.fram:findFirstChild( "label" )) then |
09 | m = playergui.titel.fram.label; -- get label from each playergui |
10 | end |
11 | end |
12 | end |
13 | if (m) then -- make sure the label exists |
14 | m.Text = "Testing" ; |
15 | end |
16 | end |
17 | end |
I added in a few if-statements so that you could check to make sure that each element existed, and avoid any errors.
Some of the code might be a bit beyond the scope of 'beginner scripting', but I'd urge you to try looking into anything there that you don't fully understand :P