(help), what do I have to do to make it work

Hi, this is a script to activate a ScreenGui, which supposedly gives me two options to buy and close, but everything is fine, except that I want only one person to be activated, not the whole server

Script: “StarterPlayer” - “StarterPlayerScripts” Is a Local Scripts

local Player = game.Players.LocalPlayer

local PlayerGui = Player:WaitForChild("PlayerGui")

local function onTouched(hit)

local Open = PlayerGui.BuyZoneUnderwater:WaitForChild("Hijo")

if hit.Parent:FindFirstChildWhichIsA('Humanoid') then

Open.Visible = true

end

end

game.Workspace.Portales.PortalUno.Touched:Connect(onTouched)
2 Likes

LocalScripts only work on the Client (a player playing the game), so your GUI will not appear on the entire server. Only for the Client.

Yes, that’s why it’s in a local script

Maybe relocate it to StarterGui and see if that works???

Still doesn’t work for me :frowning:

Are you getting any errors in the output?

It does not skip errors in the output because it is a script that works, the problem is that when it is opened all the people on the server can also see it, in addition, it is a LocalScript

Use Players:GetPlayerFromCharacter() and compare that to Players.LocalPlayer. If both are the same, then show the GUI.

Everyone can see the ScreenGui because you don’t check that the person that touched the portal is the LocalPlayer

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local PlayerGui = Player:WaitForChild("PlayerGui")

local function onTouched(hit)
	local Open = PlayerGui.BuyZoneUnderwater:WaitForChild("Hijo")
	if hit.Parent:FindFirstChildWhichIsA('Humanoid') then
		local Player = Players:GetPlayerFromCharacter(hit.Parent) -- Get the player from the touched part's character
		if Player and Player == LocalPlayer then -- Check if the character belongs to a player and the player that touched the part is the LocalPlayer
			Open.Visible = true
		end
	end
end

game.Workspace.Portales.PortalUno.Touched:Connect(onTouched)

Not working yet, bro

Try using the script I sent above

I get an error on line 4 :frowning:

Can you clarify what the problem is? And how you want your GUI to work?

You are indexing Player variable (which is nothing) instead of LocalPlayer variable.

What I want to do is that not all players see the ScreenGui but the player who touched it

In your latest picture, you use a Script. Try using a LocalScript.

It is a localscript. :frowning:

Alright, as I see, you got no soloution yet to this problem. I think the script that @heII_ish sent here should work, but there was a typo which I have pointed on. As I see you didn’t realise how to fix that error on line 4, so I will just send here the whole @heII_ish’s script, but with a fix for that error.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer

local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local function onTouched(hit)
	local Open = PlayerGui.BuyZoneUnderwater:WaitForChild("Hijo")
	if hit.Parent:FindFirstChildWhichIsA('Humanoid') then
		local Player = Players:GetPlayerFromCharacter(hit.Parent) -- Get the player from the touched part's character
		if Player and Player == LocalPlayer then -- Check if the character belongs to a player and the player that touched the part is the LocalPlayer
			Open.Visible = true
		end
	end
end

game.Workspace.Portales.PortalUno.Touched:Connect(onTouched)

Sorry, didn’t notice the typo, thanks for fixing it

1 Like