Gui displaying for everyones problem*

You can write your topic however you want, but you need to answer these questions:
1. What do you want to achieve? Keep it simple and clear!

While in game, I want everyone should able to see their own PlayerGui.ScreenGui.Enabled = true.

2. What is the issue? Include screenshots / videos if possible!

I’ve look into the output to find the problem with red text. Example like this for certain player, game.Players.Joshua7ninjaX.PlayerGui.ScreenGui.Enabled = true [Worked]
but I don’t want certain player, i want it include everyone ScreenGui should Enabled = true

3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I explained it already game.Players.Joshua7ninjaX.PlayerGui.ScreenGui.Enabled = true it is a solution, but that is not everyone getting it and i tried something like this.

GuiVisible = script.Parent

local player = game.Players.LocalPlayer

GuiVisible.Touched:Connect(function(player)
wait(5)
game.Players.LocalPlayer.Character.PlayerGui.FileMorphLoaded.Enabled = true
end)

DM anytime

1 Like

Judging by the error, this is a Script. Not a localscript. (LocalPlayer is not a variable on the Server. LocalScripts are the only thing that can access LocalPlayer.)
If you want it to show for everyone, try this.

GuiVisible.Touched:Connect(function(part_that_touched) – Get the touched event.
for Index,Player in pairs(game:GetService(“Players”):GetPlayers()) do – Loop through the players in the game.
Player.PlayerGui.FileMorphLoaded.Enabled = true – Enable the GUI for each player.
end
end)

2 Likes

There appear to be two problems here, one being that you are trying to get the LocalPlayer with a normal script, the second being that, when anything is touched, the code you intended for one player fires.

For the both problems, touched’s first parameter is the part that it touched, if it is a bodypart, it must be a child of the character, so, you can get the player with the function PlayersService:GetPlayerFromCharacter

like such

GuiVisible.Touched:Connect(function(hit)
   local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
   if plr then
       plr.PlayerGui.FileMorphLoaded.Enabled = true
   end
end)

The reason this works is because all bodyparts are children of the character.

This solves both problems as, it checks if it is a bodypart, rather than just any part, which solves the 2nd problem. Then, it only applies the changes to that player, which solves the 1st problem

Alternatively, you can do this locally aswell, just be sure to check whether the player who touched the part is the localplayer

local lplr = game.Players.LocalPlayer
local GuiVisible = workspace.Part

GuiVisible.Touched:Connect(function(hit)
   local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
   if plr == lplr then
      lplr.PlayerGui.FileMorphLoaded.Enabled = true
   end
end)
1 Like

Greetings! :wave:

The LocalPlayer variable of Players in only available on the client. Trying to access it from the server will throw an error. To resolve this issue we need to use RemoteEvents.

The Touched event comes with a argument which is the part it collided with, we can use this to find if it’s a player and which one.

Script.Parent.Touched:Connect(function(Hit) 
    if Hit.Parent:FindFirstChild("Humanoid") then
    -- A player touched the part! 
    end 
end

Now, let’s use a RemoteEvent. These objects let you communicate with the client. You can add a RemoteEvent using the + icon next to the selected object. Let’s add one inside of ReplicatedStorage, since both the server and client can access it. Name it “ShowUI”.

Great! Let’s use this to communicate with the client!

Script.Parent.Touched:Connect(function(Hit) 
        if Hit.Parent:FindFirstChild("Humanoid")  then
        -- A player touched the part! 
    game:GetService("ReplicatedStorage").ShowUI:FireAllClients() 
    end 
end

Take note how we need dont need any arguments when calling all the clients.

Now, let’s add a localscript inside of, let’s say StarterGui. This script will recieve the call and enable the ui.

game ReplicatedStorage.ShowUI.OnClientEvent:Connect(function() 
    --Enable UI here 
end

This can be quite confusing at first. If you want a better explaination, try searching something around the lines of “Roblox RemoteEvent Tutorial” In your web browser.

The reason it’s this complicated is beacuse we can’t trust the player (aka the client). They might run bad code which the server then replicates to all other players. This model prevents this and is currently mandatory on Roblox. It is also known as FilteringEnabled or FE for short.

2 Likes

Fantastic i just have to walk around within second, then it work

from the Touched through the (part_that_Touched)

Is it possible for me to adapt, PlayerAdded (just Join the game i mean)

Thank for your support i might try this one too

Please elaborate on what you want it to do with PlayerJoined.

Script deliver itself for (PlayerJoined), when player joined then wait(5) ScreenGui.Enabled = true

So you want to enable the screengui when someone joins?

If so, here’s your solution.

Put the GUI in StarterGui, no point in scripting something that was done for you by ROBLOX.

I understand that, I tried to share the video for post, it just won’t work. Thank you for help anyway.