0

# How to print out the players name?

Edited 6 days ago

Hello everyone, this is my second post here, and i have another question How do i print out the players name, yes i know this is pretty easy, but i tried some methods, it did not work, it always said: attempt to index nil with Name heres the script, i made a lava-like part, that kills you, and will print out the victims name

local lava = script.Parent -- making the lava variable
local players = game:GetService("Players")
local player = game.Players.LocalPlayer

local function killPlayer(otherPart) --the otherPart is what the object got touched with, a player touched the object with right foot,and then the script checks if its from a humanoid
local partParent = otherPart.Parent
local human = partParent:FindFirstChild("Humanoid")
human = partParent:WaitForChild("Humanoid")
if human.Health == 0 then
end
if human then
human.Health = 0
end
end

lava.Touched:Connect(killPlayer)


(you might also tip me some scripting tips)

0

You cannot get the local player using a server script. We can use GetPlayerFromCharacter for this!

local lava = script.Parent
local players = game:GetService("Players")

function KillPlayer(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local Player = players:GetPlayerFromCharacter(Hit.Parent)

if Player then
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")

if Humanoid.Health > 0 then
Humanoid.Health = 0
else
end
end
end
end

lava.Touched:Connect(KillPlayer)

0
Change it to print("player is dead:" .. Player.Name) in line 14 SEAN_YT213 104 — 6d
0
Thanks alot, this worked, and i will remember this Artemiygogolev 4 — 6d
0
No probs SEAN_YT213 104 — 6d