Just a quick simple question; as it this just came to me.
If there’s no difference what do you recommend I use instead? – I’ve always used :IsA()
.
The typeof() of any roblox instance will always return an “Instance”. This is useful, for example, when you want the client to send the server an existing instance on the server, so to know that it has sent you an instance and not a table that pretends to be an instance, you can use typeof()
Oh, I know, but they both do the exact same thing here in this context.
try this:
local instance = Instance.new("Part")
local fakeInstance = { Size = Vector3.new(3,3,3) }
for i, v in { instance, fakeInstance } do
warn(v.Size)
end
for i, v in { instance, fakeInstance } do
if typeof(v) ~= "Instance" then return end
warn(v.Size)
end
I know, so you’re saying there’s no difference (in this context)? If so, what do you recommend I use?
I got this.
But I’m not sure what you’re trying to say with this code exmaple. Because you could just do this in the if-statement in the bottom for-loop “if not v:IsA("BasePart") then return end
”
Also, just a quick irrelevant question, when you create instances without .Parent
being set, in your game (studio or playing the game on Roblox, doesn’t matter), do they eventually get deleted?
I understand that yes but after a while. So try to avoid that.
I’m sorry, I’m not sure what you mean by that.
typeof() returns the type of the instance, not the class.
example, If I used Object:IsA('BasePart')
itll return if its a BasePart, if I used typeof(Object)
, its going to return the type of the Object, which in this case is an Instance.
if you use typeof() on a string, it’ll return “string” cause its a string.
so tldr; it returns the type of the given value. Where as IsA() only works on Instances, and determines what Class said Instance is.
I mean it will stay there for a while taking up space so you should avoid it.
And from what you showed me, if you look at the first iteration it prints both the instance and the fake one, but in the second it only prints the one that is actually an instance.
Yes, I know that, but I just wanted to know- (ok I’ll put it this way instead:) What would be “better” in checking if an Instance is (in this contexet) a ModuleScript?
I don’t know what “tldr” mean, not good with abbreviations haha, sorry. Also again I know, but what would be “better”, as they both do the exact same thing in this context.
but it gets deleted right?
Yes, I know.
well if you dont know if the ModuleScript is an Instance, then I would start by doing
if typeof(value) == 'Instance' then
if value:IsA('ModuleScript') then
print('Its a module :]')
end
end
if you do know for a fact that its going to be an instance, you can just skip over using typeof().
tldr stands for too long, didnt read or something like that :]
yes, it will be removed.
No I didn’t mean that, but thank you for trying anyway
No clue what that means but thank you anyhow.
its basically a summary of everything that was said before that.
I hope that makes sense lol
so what it sounds what you want is to know if you should use typeof() or IsA() to determine if something is a ModuleScript, is that correct?
Yeah, I just found out you could do this today, and just wanted to know the difference (which now I do), and now I want to know if putting typeof()
would be “better” than :IsA()
.
no IsA() would be better, cause if you used typeof() on a ModuleScript it’d return “Instance”.
So to determine if something is a ModuleScript use IsA()