Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
174gb 290 Moderation Voter
3 years ago
Edited 3 years ago

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)
0
you are amazing tysm!! :) JustBenHD 2 — 3y
0
hey uh theres a glitch, where if the player leaves they are stuck on the board JustBenHD 2 — 3y
Ad

Answer this question