Open GUI part just for one player

  1. I want to achieve a part than open gui

  2. The gui open to everyone in server, no just to the one that tpuch the part

  3. I have been looking for different solutions but doesnt work

Heres the script

script.Parent.Touched:Connect(function(hit)
     for i,v in pairs(game.Players:GetPlayers()) do
           if v.PlayerGui then
			   v.PlayerGui.shop.panel.Visible = true
               wait(5)
			   v.PlayerGui.shop.panel.Visible = false
           end
     end
end)

Thanks for read :smiley:

Could you rephrase your question? Itโ€™s really confusing.

2 Likes

I just want that the player who touch the part see the gui

What you can do is:

You use the .Touched event to get the player, which goes as following:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    end
end)

Now, you can easily disable their GUI. You can do this with a RemoteEvent or you can do it server-sided, which I donโ€™t recommend.

Server-sided way:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
      player.PlayerGui.shop.panel.Visible = true
      wait(5)
      player.PlayerGui.shop.panel.Visible = false
    end
end)

Iโ€™m not sure if that works, I typed it in a rush. Let me know.

My problem is that if one player touch part, the gui frame show to all in server

You could do this:

local Players = game:GetService("Players")
local Part = script.Parent

local function Touched(Hit)
	local Character = Hit:FindFirstAncestorOfClass("Model")
	
	if Character then
		local Player = Players:GetPlayerFromCharacter(Character)
		
		if Player then
			local Panel = Player:WaitForChild("PlayerGui"):WaitForChild("shop"):WaitForChild("panel")
			
			Panel.Visible = true
			
			wait(5)
			
			Panel.Visible = false
		end
	end
end

Part.Touched:Connect(Touched)

Yes, It works thank you! :smiley:

I think you need to fire an on all players event.

Oh, sorry, I just saw you wanted a single player then I think you need a localevent.