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

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

Asked by 3 years ago

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)
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. greatneil80 2647 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)

0
add .Name in the print "print(playerName.Name)" VikkiVuk 74 — 3y
Ad

Answer this question