Hto open Gui to a specific Player

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!

I want to open a specific Gui to a Player

Script1:

local MobModule = require(script.Mobs)
local SpawnBalloon = game.ReplicatedStorage:WaitForChild("SpawnBalloon")
local SpawnTower = game.ReplicatedStorage:WaitForChild("AddTower")
local Information = game.ReplicatedStorage:WaitForChild("MainGame"):WaitForChild("Information")
local GameStarted = game.ReplicatedStorage:WaitForChild("MainGame"):WaitForChild("GameStarted")
local Rounds = game.ReplicatedStorage:WaitForChild("MainGame"):WaitForChild("Rounds")
local OpenGui = game.ReplicatedStorage:WaitForChild("OpenGui")
local StartingCash = 100

local function GiveCash(Player, Amount)
	Player.PlayerData.Cash.Value = Player.PlayerData.Cash.Value + Amount
end

local function SetHealth(Char)
	local Hum = Char:FindFirstChildWhichIsA("Humanoid")
	local GuiClone = game.ReplicatedStorage.HealthGui:Clone()
	GuiClone.Parent = Char


	--// Scripting HealthBar \\--
	
	if Char.Name == "Base" then
		GuiClone.MaxDistance = 350
		GuiClone.Size = UDim2.new(20,0,5,0)
	else
		GuiClone.MaxDistance = 80
		GuiClone.Size = UDim2.new(10,0,2.5,0)
	end

	local colorGreen = Color3.fromRGB(0, 255, 0)
	local colorRed = Color3.fromRGB(255, 0, 0)
	
	local Health = Hum.Health
	local MaxHwalth = Hum.MaxHealth
	local Percentage = Health / MaxHwalth

	GuiClone.TextLabel.Text = GuiClone.Parent.Name..": "..Health.."/"..MaxHwalth
	GuiClone.Health.Size = UDim2.new(Percentage, 0, 1 ,0)
	GuiClone.Health.BackgroundColor3 = colorRed:Lerp(colorGreen, Health / MaxHwalth)
	
	Hum.HealthChanged:Connect(function()
		local Health = Hum.Health
		local MaxHwalth = Hum.MaxHealth
			local Percentage = Health / MaxHwalth
		
		GuiClone.TextLabel.Text = GuiClone.Parent.Name..": "..Health.."/"..MaxHwalth
		GuiClone.Health.Size = UDim2.new(Percentage, 0, 1 ,0)
		GuiClone.Health.BackgroundColor3 = colorRed:Lerp(colorGreen, Health / MaxHwalth)
	end)
end

while wait() do
	if #game.Players:GetPlayers() < 1 then
		Information.Value = "Not Enough Players"
	else
		for i = 10,0,-1 do
			Information.Value = "Game Starting In "..i
			wait(1)
			if i == 0 then
				local RandomPlayer = game:GetService("Players"):GetChildren()[math.random(1,#game:GetService("Players"):GetChildren())]
				print(RandomPlayer.Name)
				for i, v in pairs(game.Players:GetPlayers()) do
					GiveCash(v, StartingCash)
					
					if v.Name == RandomPlayer.Name then
						v.PlayerData.IsImposter.Value = true
						OpenGui:FireClient(v, v.PlayerGui:FindFirstChild("TowerGui"))
					else
						v.PlayerData.IsImposter.Value = false
						OpenGui:FireClient(v, v.PlayerGui:FindFirstChild("BalloonGui"))
					end
				end
				GameStarted.Value = true
				workspace.Balloons.ChildAdded:Connect(function(Object)
					coroutine.wrap(SetHealth)(Object)
				end)
				coroutine.wrap(SetHealth)(workspace.Base)
				SpawnBalloon.OnServerEvent:Connect(function(Player, BalloonName)
					MobModule.Spawm(BalloonName)
				end)
			end
		end
		break
	end
end

Script: 2

local MoneyFrame = script.Parent.MoneyFrame
local Player = game.Players.LocalPlayer
local PlayerDataFolder = Player.PlayerData

while wait() do
	MoneyFrame.TextLabel.Text = "Cash: "..PlayerDataFolder.Cash.Value
end


game.ReplicatedStorage.OpenGui.OnClientEvent:Connect(function(PLR, plrGui)
	plrGui.Enabled = true
end)

Game Name: Bloons TDS X

In LocalScripts, the player variable doesn’t exist. You’ll have to remove that.
You can clone the gui you want to show to the player’s gui, (game.Players.PlayerName.PlayerGui) and then make it visible. You need to remember to put it in a ScreenGui too.

1 Like

I know this is not a solution but why are you using while loops

use GetPropertyChange signal instead

PlayerDataFolder.Cash:GetPropertyChangeSignal("Value"):Connect(function()
	MoneyFrame.TextLabel.Text = "Cash: "..PlayerDataFolder.Cash.Value
end)
MoneyFrame.TextLabel.Text = "Cash: "..PlayerDataFolder.Cash.Value

You mean like this?

game.ReplicatedStorage.OpenGui.OnClientEvent:Connect(function(plrGui)
	local Clone = plrGui:Clone()
	Clone.Enabled = true
end)

Oh i know the problem the plrGui Arg is NIL WHY IS THIS HAPPINING

Screenshot 2022-08-11 094334

i think its because my internet is very slow i think the player loads very slow and the script runs very fast

wait i will go to a place where the internet is best

Dont open vvvvvvv

Ok im back, THIS IS A SECRET WHY DID YOU OPEN ME!!!1

Not with OnClientEvent. It comes from the server.

This time it printed nothing but it still didnt worked

Make RemoteEvent on server call :FireClient(player, thegui)
On client just listen on OnClientEvent and you will the theGui as the argument

what do you mean by that i dont understand a thing

What i removed the clone thingy and it worked i… i didnt event need to create this topic it was just the network that was bad

i replaced v to RandomPlayer and it still works i will put RandomPlayer so it dosent put the Gui for everyone

i tried play testing and it still works