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

Can't seem to find username from script?

Asked by 5 years ago

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)
0
There is no "Player" under workspace. Best way to find the player is by using the Touched event. RAYAN1565 691 — 5y

1 answer

Log in to vote
0
Answered by
RAYAN1565 691 Moderation Voter
5 years ago
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)   
0
Thank you! That worked perfectly. samual123456 2 — 5y
1
If I answered your question, please make sure to accept it as an answer. RAYAN1565 691 — 5y
Ad

Answer this question