Still have questions? Join our Discord server and get real time help.
0

# How to find player's username upon Touched event?

Please note that this is a rather long question and contains multiple scripts.

The following scripts associate a WORKING timer for my Ninja Warrior tournament:

Script 1 (The Timer):

local bool = true
script.Parent.Touched:Connect(function()
if bool == false then return end
bool = false
if script.Parent:FindFirstChild("Humanoid") ~= nil then
for i = 100,0,-1 do
wait(1)
for _,p in pairs(game.Players:GetPlayers()) do
p.PlayerGui.ScreenGui.Timer.Text = i..""
end
if i == 0 then
for _,v in pairs(game.Players:GetPlayers()) do
p.PlayerGui.ScreenGui.Timer.Text = "Failure!"
end
end
end
end
wait(3)
bool = true
end)


Script 2 (Clear Button):

local bool = true
script.Parent.Touched:Connect(function()
if bool == false then return end
bool = false
if game.Workspace["Stage 1 Start Button"].Script.Disabled ~= true then
game.Workspace["Stage 1 Start Button"].Script.Disabled = true
end
for _,p in pairs(game.Players:GetPlayers()) do
p.PlayerGui.ScreenGui.Timer.Text = "Clear!"
end
end)


Before line 8 in Script 2, I want to know how to find a player's username and show it with lines 8 and 9. Any help would be appreciated.

0
if the part is touched, should the player that touched it gets the changed text? ieatandisbaconhair 77 — 9mo
0
You're not going to be able to manipulate player's PlayerGui in a script Vulkarin 580 — 9mo
0
this might work mabye idk Donut792 112 — 9mo
0
@Vulkarin the script works RobloxWhizYT 2131 — 8mo

2
RAYAN1565 691
9 months ago

How to find the player's username using the Touched event?

Try to incorporate the below code into your script(s):

script.Parent.Touched:Connect(hit)
if hit.Parent:FindFirstChild("Humanoid") then
end
end

0

Hey I'm BlackOrange and I will be attempting to help.

RAYAN1565 answer is correct to some degree, but to 100% guarantee that what touched the part is INDEED a PLAYER, then you would use :GetPlayerFromCharacter. This is basically a better improved way since the script above provided would show a NPC's name if the npc happened to slight touch the part.

script.Parent.Touched:Connect(function(h)
if h.Parent:FindFirstChild('Humanoid') and game:GetService('Players'):FindFirstChild(h.Parent.Name) then
local plr = game.Players:GetPlayerFromCharacter(h.Parent)
local Name = plr.Name
end
end)


Hopefully this will help improve your script.

Best of luck developer!