0

# Is it possible to display player's usernames on a surface gui if they are touching a specific block?

So basically if they are touching a part called 'detector' their username will be shown on a surface UI. If there's multiple it would display it as USER1, USER2

Is this possible and how would you do it?

0
sO_Ov 275
8 days ago
Edited 8 days ago

Here's a example (i'd recomend use Region3 instead Touch Events)

--Important: Your detection part must be more high than players avatar

local Players = game:GetService("Players")
local touchPart = script.Parent.touchPart -- your detection part
local touchingPlayers = {} -- create a table to store players that are touching

touchPart.Touched:Connect(function(obj) -- when the part is touched
if obj.Parent:FindFirstChild("Humanoid") then -- check if who's touched the part has humanoid
if Players:GetPlayerFromCharacter(obj.Parent) then -- check if the object is a player
if not table.find(touchingPlayers, obj.Parent.Name) then -- check if player name isn't already on table
table.insert(touchingPlayers, obj.Parent.Name) --insert player name on table
end
surfaceGui.TextLabel.Text = table.concat(touchingPlayers, ', ') -- concat all strings on the table
end
end
end)

touchPart.TouchEnded:Connect(function(obj) -- when someone has 'untouched'  the part
if table.find(touchingPlayers, obj.Parent.Name) then -- check if is in table
table.remove(touchingPlayers, table.find(touchingPlayers, obj.Parent.Name)) -- remove from table
surfaceGui.TextLabel.Text = table.concat(touchingPlayers, ', ') -- update surface text
end
end)

0
you are amazing tysm!! :) JustBenHD 2 — 7d
0
hey uh theres a glitch, where if the player leaves they are stuck on the board JustBenHD 2 — 6d