How to make a gui apear on one persons screen?

I want to make a simulator game so you click and you get no’s. So I want to make a gui that apears on only the person that clicks like +1 No or something. I already made something that does that but I think its showing on every people’s screen becouse its in a regular script. So my question is how do I make the gui only appear on 1 person’s screen?

The script I made:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local IncreaseNo = ReplicatedStorage.RemoteEvents.IncreaseNo
local InLoop = false

local Pos1 = math.random(140, 920)
local Pos2 = math.random(109, 403)

IncreaseNo.OnServerEvent:Connect(function()
if InLoop == false then
InLoop = true
script.Parent.ImageLabel.ImageTransparency = 0
script.Parent.ImageLabel.Position = UDim2.new(0, Pos1, 0, Pos2)
script.Disabled = true
wait(0.1)
script.Disabled = false
for i = 1, 40, 1 do
script.Parent.ImageLabel.ImageTransparency += 0.025
wait(0.0125)
end
wait(0.5)
InLoop = false
end

if InLoop == true then
script.Parent.ImageLabel.ImageTransparency = 0
end
end)

You add the Gui into their PlayerGui.

Interface.Parent = Player.PlayerGui

or, you can have the code fire for their Client only

PlayerGui is what the Player see’s on their screen, and each Player has a separate PlayerGui that comes from StarterGui

2 Likes

There are 3 areas that you’ll have to focus on here.

  • StarterGui
  • StarterPlayerScripts (located in StarterPlayer)
  • ReplicatedStorage

Here is a step by step process to get you to your goal.

  1. StarterGui
    Put a ScreenGui inside of the StarterGui

  2. ReplicatedStorage
    Put a TextLabel inside of ReplicatedStorage

  3. StarterPlayerScripts
    Put a local script inside of StarterPlayerScripts. Next you’ll want to get access to some things you’ll need in the future. In this case, you’ll need ContextActionService (to detect mouse input), ReplicatedStorage (to find your TextLabel), your TextLabel (for creating the numbers), and finally your PlayerGui (to put the TextLabels in). Here is what your script should look like:

local ContextActionService = game:GetService('ContextActionService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ScreenGui = game.Players.LocalPlayer:WaitForChild('PlayerGui', 20):WaitForChild('ScreenGui', 20)
local TextLabel = ReplicatedStorage:WaitForChild('TextLabel', 20)

Now that you have access to what you need, you can code the input function when the player clicks using ContextActionService:BindAction() This function of ContextActionService needs a function to call during input, so we’ll also create a function called OnClick Inside that function, we’ll check if the input is Begin or End to see if the mouse is up or down. If it’s End, we will stop because we only want the function to run once per mouse click. Your code should now look like this.

local ContextActionService = game:GetService('ContextActionService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ScreenGui = game.Players.LocalPlayer:WaitForChild('PlayerGui', 20):WaitForChild('ScreenGui', 20)
local TextLabel = ReplicatedStorage:WaitForChild('TextLabel', 20)

local function OnClick(Name, InputState, InputObject)
	--Check that the mouse was just clicked
	if not (InputState == Enum.UserInputState.Begin) then
		return
	end
end

ContextActionService:BindAction(
	'Click',
	OnClick,
	false,
	Enum.UserInputType.MouseButton1
)

Now we can add the rest of what happens during a mouse click into that function OnClick. To create a text label, we’ll call our variable TextLabel and use TextLabel:Clone() to create a new one. We’ll parent it to the screen GUI, give it a random position, and change the text to a random number. Finally, we’ll use task.wait(3) to wait 3 seconds before destroying the text label.

Here is what your final code should look like:

local ContextActionService = game:GetService('ContextActionService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ScreenGui = game.Players.LocalPlayer:WaitForChild('PlayerGui', 20):WaitForChild('ScreenGui', 20)
local TextLabel = ReplicatedStorage:WaitForChild('TextLabel', 20)

local function OnClick(Name, InputState, InputObject)
	--Check that the mouse was just clicked
	if not (InputState == Enum.UserInputState.End) then
		return
	end
	
	--Get your random position (using the AbsoluteSize property of your ScreenGui)
	local RandomPosition = UDim2.new(0, math.random(0, ScreenGui.AbsoluteSize.X), 0, math.random(0, ScreenGui.AbsoluteSize.Y))
	
	local Label = TextLabel:Clone()
	Label.Parent = ScreenGui
	Label.Position = RandomPosition
	
	--Create your random number
	Label.Text = '+'..math.random(1, 100)
	
	task.wait(3)
	Label:Destroy()
end

ContextActionService:BindAction(
	'Click',
	OnClick,
	false,
	Enum.UserInputType.MouseButton1
)

If any step in this process is too difficult to understand, I recommend watching youtube videos on how to achieve something like this. They will be able to show you clearly and visually.

1 Like

I will test this right now ty alot!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.