I need to print out the player's name in the console when they touch a brick with their character, but my code doesn't work. can anyone help me solve this issue?
--variables local brick = script.Parent --functions local function startLevel(player) print(player.Name) end --code brick.Touched:Connect(startLevel(otherPart))
Here's an easier way:
local brick = script.Parent function startLevel(hit) if hit.Parent then if hit.Parent:FindFirstChild("Humanoid") then print(hit.Parent.Name) end end end brick.Touched:Connect(startLevel)
Here's how this works: Once the function is fired (when the brick is touched) it checks does the object that hit the brick still exist, if it does, then it checks does the object's Parent (Obviously the character) have a Child called "Humanoid", if it does, we can be sure the toucher was a player, and then print the player's/character's Name.
You did the variable defining correctly, but use this function instead.