Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does My Log say this attempt to index nil with 'Name'?

This is a Server Script

local part = script.Parent

--player--
local Player = game:GetService("Players").LocalPlayer
local PlayerName = Player.Name

part.Touched:Connect(function(touch) 
	
	if touch.Parent:FindFirstChild("Humanoid") then 
		
		print(PlayerName)
	
	end
end)

1 comment

0

thats a regular script and LocalPlayer doesn't exist in a regular script. Another thing is that the PlayerName won't print who touched the part.

1 answer

local part = script.Parent

--player-- local Player = game:GetService("Players")

local gui = part.SurfaceGui.nameGui local data = script.Parent.Parent.Parent:WaitForChild("Data") local owner = data.Owner local claimed = data.Claimed

part.Touched:Connect(function(touch)

if touch.Parent:FindFirstChild("Humanoid") then 
	
	
local playerName = Player:GetPlayerFromCharacter(touch.Parent) --Gets Players Name
print(playerName)

end

end)

1 comment

0

add .Name in the print "print(playerName.Name)"

This discussion is preserved as it was. New answers, comments, and votes are closed.