Gamemodes - Floating name above head! Error

Ok so ive been trying to add floating names above players heads in my gamemode and im getting an error of a missing bracket?
Heres the code - not sure if its right but mind if you people have a look?



/*---------------------------------------------------------
  Names above peoples heads
---------------------------------------------------------*/
function HoveringNames()
	
local ply = LocalPlayer()
for id, target in pairs(ents.FindByClass("Player")) do
	
	if target:Alive() then
		
		local name = tostring(Target:Nick())
		local targetPos = target:GetPos() + Vector(0,0,64)
		local targetDistance = math.floor((ply:GetPos():Distance( targetPos ))/40)
		local targetScreenpos = targetPos:ToScreen()
		
		surface.SetTextColor(200,25,25,100)
		surface.SetFont("Trebuchet18")
		surface.SetTextPos(tonumber(targetScreenpos.x), tonumber(targetScreenpos.y))
		surface.DrawText("Player: "..tostring)
			
		end
	end
end
hook.Add("HUDPaint", "HoveringNames" "HoveringNames")


[del]I can’t see it right away, what line does it say the error is occurring on?[/del]

For starters, it looks like you’re missing a comma on the last line.

Also, double check the hook.Add documentation here.

if it helps you, this is the servers log http://s921.photobucket.com/albums/ad60/stu564/?action=view&current=hlp.jpg

Use player.GetAll() to get the table of players.

Just edited my post, I think it’s confused because you’re missing a comma, but check out the documentation I linked to as well, the parameters should be String, String, Function.

Untested
[lua]/---------------------------------------------------------
Names above peoples heads
---------------------------------------------------------
/
function HoveringNames()

surface.SetTextColor(200,25,25,100)
surface.SetFont("Trebuchet18")
local ply = LocalPlayer()
for _, target in pairs(player.GetAll()) do
	if target:Alive() then
	
		local name = target:Nick()
		local targetPos = target:GetPos() + Vector(0,0,64)
		local targetDistance = math.floor((ply:GetPos():Distance( targetPos ))/40)
		local targetScreenpos = targetPos:ToScreen()
		
		
		surface.SetTextPos(tonumber(targetScreenpos.x), tonumber(targetScreenpos.y))
		surface.DrawText("Player: "..target:Nick())
		
	end
end

end
hook.Add(“HUDPaint”, “HoveringNames”, HoveringNames)[/lua]

[HR]Testing it now… be a min[/HR]

Yeah its working thanks!

If you’re still in the thread, i would much more recommend you use draw.SimpleText for it’s allignment argument.

[lua]function HoveringNames()

for _, target in pairs(player.GetAll()) do
	if target:Alive() and target != LocalPlayer() then
	
		local targetPos = target:GetPos() + Vector(0,0,84)
		local targetDistance = math.floor((LocalPlayer():GetPos():Distance( targetPos ))/40)
		local targetScreenpos = targetPos:ToScreen()
		draw.SimpleText(target:Nick(), "Trebuchet18", tonumber(targetScreenpos.x), tonumber(targetScreenpos.y), Color(200,25,25,200), TEXT_ALIGN_CENTER)
		
	end
end

end
hook.Add(“HUDPaint”, “HoveringNames”, HoveringNames)[/lua]

ill test it out soons :stuck_out_tongue: thanks for the help!

Edit - Works great! awards lua medal