I am trying to make a script to print to the output whenever somebody touches one of the KillBricks in my game (I am making an obstacle course with laser parts that kill you) with their username. I want to achieve this as it might be useful information later in my development of the game.
Here is the script I am trying to use:
function onTouched(Obj)
local Character = Obj.Parent:FindFirstChild("Humanoid")
if Character then
Character.Health = 0
end
end
script.Parent.onTouched(function(player)
local username = player.Name
print(username.Name)
end)
script.Parent.Touched:Connect(onTouched)
Whenever I touch one of the lasers however, nothing goes into the output!
script.Paremt.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent) -- Gets Player by Character
if player then -- if there is a Player (function may return nil)
print(player.Name)
end
end)