How do I let pop the Gui on both player?

Hey,

how can I let the gui pop up on 2 player when they touch the part?

Here is what I am thinking:

ServerScriptService:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		game.Workspace.Baseplate.Touched:Connect(function(hit)
		        Remote:FireServer()
		end)
	end)
end)

StarterGui:

but How can I let it pop up for both player?

This is what I am thinking but once I tested out and it didnt work, so let me explain:

Get the player name and let a gui clone on his screen - we do this with touch event

This should work or am I wrong? if yes is there a better way? or if that doesnt work give me an idea.

2 Likes

You could use the server to duplicate a copy of the popup into their PlayerGui’s

Remote.OnServerEvent:Connect(function(Player)
	local Clone1 = ScreenGui:Clone()
	local Clone2 = ScreenGui:Clone()
	Clone1.Parent = Player.PlayerGui
	Clone2.Parent = Player2.PlayerGui
end)

edit:Like that?

Edit2: The ScreenGui could be like in Replicated Storage

1 Like

but I want make that with touch event hmm?

the code you had in the beginning, Then the code i have in a serverscript

wait what? I cant udnerstand you. Could you explain me better?

wait i thought that was in a localscript, my bad, if its in serverscript, you shouldnt :FireServer(), and you can parent clones of the GUI in their PlayerGui

local ScreenGui = --Put your screenGui containing your popup
local player2 = --Player2

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		game.Workspace.Baseplate.Touched:Connect(function(hit)
			local Clone1 = ScreenGui:Clone()
			local Clone2 = ScreenGui:Clone()
			Clone1.Parent = plr.PlayerGui
			Clone2.Parent = Player2.PlayerGui
		end)
	end)
end)

wait i thought that was in a localscript, my bad, if its in serverscript, you shouldnt :FireServer(), and you can parent clones of the GUI in their PlayerGui

and how can I get Player2???

what do you mean here? you mean they need to be on the part at the same time?

how can I get the second player?? Like I said: how can I get Player2???

I want get the one

Alright, If you want to get 2 players on a thing at the same time do something like

local Block = --Put Part
local GUI = --PutScreenGui
local playersFound = false

spawn(function()
	repeat
		local Table = Block:GetTouchingParts()
		local Players = {}
		for i,v in ipairs(Table) do--How we gett our players touching the part
			local Player = game.Players:GetPlayerFromCharacter(v.Parent)
			if Player and not table.find(Players, Player) then --Player does exist and is not in table
				Players[#Players+1] = Player
			end
		end
		if Players[1] and Players[2] then
			GUI:Clone().Parent = Players[1].PlayerGui
			GUI:Clone().Parent = Players[2].PlayerGui
			playersFound = true
		end
		wait(0.01)--Decrease this for faster response, Increase this for less lag(if there is any)
	until playersFound = true
end)
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		game.Workspace.Baseplate.Touched:Connect(function(hit)
		    game:GetService("ServerStorage").GUI:Clone().Parent = plr.PlayerGui
		end)
	end)
end)

Take this as an example. Whenever the part is touched, it clones the GUI and moves it into PlayerGui. Modify it for your needs.

okey but I dont want clone exactly. It just have to pop up the screen. So the Gui is there at the beginning of the game

but I just want once and also on both player

Are you wanting to replicate it across all players when the Baseplate first gets touched?

No, look. The player will have at the beginning of the game a Gui. When the player touches the base plate then the two player pops up a gui at their screen. Btw the gui goes visible

Your idea is really good but I seriously dont like like it how you did it and also it doesnt work

If you want a gui to pop up on players once they touch the baseplate:

local Players = game:GetService('Players')

local gui = --gui object that will pop up
local base = --the baseplate

Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local touched = false -- so it doesnt repeat

base.Touched:Connect(function(hit)
if hit.Parent == char and not touched then
local guiClone = gui:Clone()

touched = true
guiClone.Parent = player.PlayerGui
end
end)
end)
1 Like

ServerScriptService:

-- You don't need all that for checking a touched event
game.Workspace.Baseplate.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)

    -- Checks if player exists
    if player then
        Remote:FireClient(player)
    end
end)

StarterGui

-- If the event is fired
Remote.OnClientEvent:Connect(function()
    local frame = PATH_TO_FRAME
    -- Make frame visible, tween it using :TweenPosition, etc
end)