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