Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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?

1 answer

✓ Accepted answer

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

There's model link if you had some issue MODEL


--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 surfaceGui = script.Parent.surfacePad.SurfaceGui -- your surface gui
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)

2 comments

0

you are amazing tysm!! :)

0

hey uh theres a glitch, where if the player leaves they are stuck on the board

This discussion is preserved as it was. New answers, comments, and votes are closed.