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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
hit.Parent is the character, not the player. DesertusX 435 — 4y

1 answer

Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago

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!

0
The gui still won't enable PastorCL3Z 75 — 4y
0
Where is the script located? Is it a LocalScript or a ServerScript? DesertusX 435 — 4y
0
Its a Script inside of a part that kills you after 10 seconds Local. PastorCL3Z 75 — 4y
Ad

Answer this question