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

How to know which player touched a part?

I want to make a king of the hill game but im stuck on one part. i want it so when a player touches a brick it makes a billboard gui say "[player] Is now king of the hill!" but i have no idea how to make it say the username or i was thinking of trying to use the GetPlayerFromCharacter function but i dont know how to use it.

2 answers

Use .Touched:Connect(). Then check if local player = game.Players:FindFirstChild(hit:FindFirstAncestorOfClass("Model").Name) ~= nil. if it is you can use player.Name to get what you're calling [player]

Make this script inside the block (not text).

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- checks if the person is a player, not a block (if a leg touches this then the parent of it is the person, then it checks if the child humanoid exists so its a player)
local name = hit.Parent.Name -- if a leg or something is detected then the parent of it (the players name) will be here

script.Parent.SurfaceGui.BillboardGui.TextLabel.Text = name -- make the text the persons name

end

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