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

is there a way of checking if a model is in workspace??

Asked by
Hasburo 150
8 years ago

for example;

like

if game.Workspace:FindFirstChild("Model") .. checking if model is in the workspace then
end
elseif code here
end

sorry for the rookie question, I just can't think of anything rn.

also could you use isdescendantof? http://wiki.roblox.com/index.php?title=API:Class/Instance/IsDescendantOf

2 answers

Log in to vote
0
Answered by 8 years ago

There is a useful function called IsDescendantOf() which returns true if the object is a descendant of the given ancestor.

if Model:IsDescendantOf(Workspace) then 
-- Code
end

~UserOnly20Charcters, Hoped I helped you to answer your question! If you have any further question, don't hesitate to comment below!!

Ad
Log in to vote
1
Answered by
xuefei123 214 Moderation Voter
8 years ago

There is a way! You have to use a loop.

Here is an example:

local modelinworkspace = false--Change this to any variable if you want

for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "ModelName" then--Change this to your model name
modelinworkspace = true
else
print("Model not in workspace")--Just an example, this is not needed
end

Hope this helped! If it did, please accept my answer, it gives us both rep!

Answer this question