I am not going to write your code for you - in fact, that’s explicity disallowed according to the rules of #help-and-feedback:scripting-support. In order to truly understand your code, you do need to understand the elements in play and what does what. Simply copy/pasting solutions will not educate you. If you are just looking for me to give you the explicit solution, I will not - you can either attempt to solve the issue yourself or wait for someone else to give you it. I am happy to guide you on the right track, but I do not believe simply giving solutions is helpful to anyone unless it’s a strange/irritating issue that doesn’t necessarily warrant an explanation.
(I am assuming you are trying to do this with a ServerScript
. If not, please clarify, as it isn’t obvious from the code you’ve provided.)
I will attempt to be more clear, however. Your initial script is attempting to change the UI elements in StarterGui
. Big no no, because this is change is not going to be reflected to any players. If you want to change the UI of a specific player, at run-time (while the game is running), you need to instead change the elements of the PlayerGui
of that specific player. In your case, I assume you are trying to enable some LocalScripts
inside of a UI once a player spawns. What you currently have does not work.
This is because the PlayerGui
is what contains the UI elements each player sees, not the StarterGui
. Every time a player joins a server, the elements in StarterGui
are copied over (replicated) to that specific player’s PlayerGui
. This happens every time the player dies and respawns, as the contents of each individual player’s PlayerGui
are emptied once that player dies. (there is an exception to this rule that isn’t applicable here)
To fix this issue, you need to enable these elements in the player’s PlayerGui
, which I hinted to in my first response. Your first attempted solution has this erroneous line of code:
local GUI = game:GetService("PlayerGui")
This will not work, because PlayerGui
is not a service nor is it something that can be asked for from a ServerScript
without first getting the player it’s attached to. Thus, your GUI2
variables and textLabelScript
are also erroneous.
local PlayerService = game:GetService("Players")
PlayerService.PlayerAdded:Connect(function(plr)
print("Player joined")
task.wait(1)
-- Modify items in player's local UI instance
local thisPlayerGui = plr:WaitForChild("PlayerGui") -- ensure the PlayerGui has loaded
...
end)
Refer back to the second half of the code in my response. All you have to do is enable these elements in this player’s PlayerGui
. To do that, you can surf through the PlayerGui
. It will contain exactly what your StarterGui
contains. (for example, thisPlayerGui.ScreenGui.TextLabel... bla bla bla
)
Issue: your UI is not in StarterGui
. Again, I don’t know why this is the case, but if it’s for a reason you are going to have to deal with the additional hassle of manually replicating the UI to the player’s PlayerGui
. I assume this is not what you want.
To solve your issue, you need to do the following:
- Place your UI in
StarterGui
- Use the
ServerScript
that is listening for player connections to change the UI that was replicated to that player’s PlayerGui
Now, since the UI resets on a player’s death, you’ll also have to listen for when their character respawns as well. Since that’s not within the scope of this issue, I am not going to elaborate on it, but it’s a relatively easy exercise that can be left to the reader.