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