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

return name of hitter?

Asked by
j1011 0
9 years ago

If a brick is touch by a player the textlabel of billboard gui will print the name of player. The BillBoardGui is inside the "Head" both head and Script is inside the "Model" Here's my model format +Model ++Script Head +BillBoardGui ++TextLabel I don't know whats wrong to my script..

script.Parent.Touched:connect(function(hit)
s = plr:findFirstChild("Name")
parent.BillBoard.TextLabel .Text = "You have won!"..s

script.Parent.Touched:connect(onTouch)

1 answer

Log in to vote
-1
Answered by 9 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
local parent = script.Parent

parent.Touched:connect(function(hit) 
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local hitterName
    if humanoid ~= nil then
        hitterName = humanoid.Parent.Name
        parent.Billboard.TextLabel.Text = "You have won, "..hitterName.."!"
    end
end)

What the script does is: checks if the object that touched the part has a Humanoid on it's model. If it does, it most likely is a player, so we get the model name.

0
It says "Touch is not valid member of model" j1011 0 — 9y
0
Weird, what line is the error on? Tytanlore 15 — 9y
Ad

Answer this question