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

Can't seem to find username from script?

Hi, I am trying to make a model that puts the username of any player that touches a brick into a surface gui. I am having difficulty with the username and have tried different options such as the getplayerfromcharacter. Below is the code I have so far. Any help is appreciated.

local character = game.Workspace.Player
local player = game.Players:GetPlayerFromCharacter(character)

screen = workspace.Screen.SurfaceGui.Frame.TextBox
Sens = script.Parent


local function OnTouch (Sens)
 screen.Text = ("Person Reset:" ..player.Name)
end





Sens.Touched:Connect (OnTouch)

1 comment

0

There is no "Player" under workspace. Best way to find the player is by using the Touched event.

1 answer

✓ Accepted answer
function onTouch(characterBodyPart)
	local characterName = characterBodyPart.Parent.Name
	local humanoid = characterBodyPart.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local screen = workspace.Screen.SurfaceGui.Frame.TextBox
		screen.Text = "Person Reset: "..characterName
		humanoid.Health = 0
	end
end

script.Parent.Touched:Connect(onTouch)	 

2 comments

0

Thank you! That worked perfectly.

1

If I answered your question, please make sure to accept it as an answer.

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