Goddamn stupid code

So I might kick myself in the face but I don’t see how I am mucking this up.

When I try this code and look at the world the “World” text pops up for the first ent:GetClass()

but it doesn’t actually say that last elseif statement is true. The

elseif ent:GetClass() == “World” then

doesn’t work when I look at the world. Not sure why.

No errors pop up.

isn’t it “world” lowercase

The wiki is your friend.

It prints upper case when I do the check.

[editline]8th October 2016[/editline]

Yes, but I want to know why the hell this isn’t working. So this type of stupid shit doesn’t happen in the future.

Bro, just use ent:IsWorld() and call it good. Did you even read the page I linked?

shouldn’t it be

GetClass() == “worldspawn” or ent == Entity(0)

“Bro”, did you even read what I wrote?

I wanted to know why it didn’t work. Not how to fix it.

[editline]8th October 2016[/editline]

It might be “worldspawn” but then why does it print “World” to my chat when I use the :GetClass() on it?

Prints “worldspawn” for me, no idea what you’re doing

Garrys mod must be fucking autistic for me then.

Yes, worldspawn is the one that works though. Thank you.

I would calm down on the profanity, it gives out a hostile vibe, might make people not want to help.

If I had to guess, it might return something different on the client (being “World”) than it does on the server end (being “worldspawn”)

Welcome to the weird world of Garry’s Mod auto-localization. A lot of functions will helpfully* take whatever you pass in, and do a language token lookup on them. Player:PrintMessage is one such function, but it’s even weirder than usual. Ordinarily, a language token must start with a # character (e.g. “#worldspawn”). But PrintMessage does a lookup regardless, so it converts “worldspawn” to “World”, as it translates in the English locale. Note that it only does this when you call it from the server—it’ll print “worldspawn” on the client.


I rememeber some addons used to add localizations for worldspawn and trigger_hurt for example, so that it would show something else in the kill feed, maybe you have something like this installed?

I’m pretty sure that’s default, now. I just tested in dev with all of my addons disabled, and the localization is still there for both of those.

You should check IsWorld(), like so…

for _,ent in pairs( ents.GetAll() ) do
if ent:IsValid() and ent:IsWorld() then print(“I’m a world entity! :D”) end


Little would you know nothing would come of that considering IsValid would return false for the world. Also, did you even read the above replies? He was already suggested that, he just wanted to know why it didn’t work.


You could simply use
for _, ent in pairs (ents.GetAll ()) do
if ent == game.GetWorld () then print (“I’m a world entity! :D”) end