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

How To Get A Players Avatar And Username Off A Touched Event?

Hi, how can I change this script so it gets the thumbnail and username from the player? I've tried a couple of times to change the coding but nothing seems to be working

local Part = script.Parent
local PlayerWin = game.StarterGui.PlayerWin
local PlayerName = game.StarterGui.PlayerWin.Frame.PlayerName
local PlayerImage = game.StarterGui.PlayerWin.Frame.ImageLabel
local thumbnail = Enum.ThumbnailType.HeadShot



Part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local Pic = hit.Parent.thumbnail
		PlayerImage.Image = Pic
		PlayerName.Text = hit.Parent.Name
		PlayerWin.Enabled = true
			Part:Destroy()
			wait(10)
			PlayerWin.Enabled = false
				humanoid.Health = 0
	
		end	
	end)

1 comment

0

hit.Parent is the character, not the player.

1 answer

hit.Parent is the character, not the player. You need to get the player. You can do this with GetPlayerFromCharacter.

local Part = script.Parent
local PlayerWin = game.StarterGui.PlayerWin
local PlayerName = game.StarterGui.PlayerWin.Frame.PlayerName
local PlayerImage = game.StarterGui.PlayerWin.Frame.ImageLabel
local thumbnail = Enum.ThumbnailType.HeadShot
	 
	 
	 
Part.Touched:Connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local Pic = player.thumbnail
	        PlayerImage.Image = Pic
	        PlayerName.Text = player.Name
	        PlayerWin.Enabled = true
	            Part:Destroy()
	            wait(10)
	            PlayerWin.Enabled = false
	                humanoid.Health = 0
	 
	        end
	    end)

Hope this helps

Don't forget to accept the answer if I helped!

3 comments

0

The gui still won't enable

0

Where is the script located? Is it a LocalScript or a ServerScript?

0

Its a Script inside of a part that kills you after 10 seconds Local.

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