|
| 11 May 2016 05:36 PM |
How do you make a script check if a model is in the game? Like if I do this:
model = workspace.Part model:Destroy()
|
|
|
| Report Abuse |
|
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
| |
|
|
| 11 May 2016 05:38 PM |
I've tried all I can think of... Here is the script I'm trying to do.
model = workspace.Part if model.Parent == workspace then workspace.Part2.Parent = game.Lighting if model == nil then game.Lighting.Part2.Parent = workspace end end
|
|
|
| Report Abuse |
|
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
|
| 11 May 2016 05:41 PM |
If ur just checking the model is there then do
If model then |
|
|
| Report Abuse |
|
|
|
| 11 May 2016 05:43 PM |
I mean... I need it see if the model there and if its not then do something else. How do I make it do that |
|
|
| Report Abuse |
|
|
xlaser23
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 20341 |
|
|
| 11 May 2016 05:44 PM |
| If model then or if not model then |
|
|
| Report Abuse |
|
|
|
| 11 May 2016 05:47 PM |
| Okay... Then how do I make the script repeat over and over |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 11 May 2016 05:52 PM |
while true do wait() --script end |
|
|
| Report Abuse |
|
|
| |
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 11 May 2016 05:59 PM |
| then you're doing something wrong, thats an infinite loop. |
|
|
| Report Abuse |
|
|
|
| 11 May 2016 06:01 PM |
Here is the script I'm trying to repeat..
model = workspace.Part if model.Parent == workspace then workspace.Part2.Parent = game.Lighting if model then if not model then game.Lighting.Part2.Parent = workspace end end end |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 11 May 2016 06:03 PM |
| wtf are you trying to do.. |
|
|
| Report Abuse |
|
|
|
| 11 May 2016 06:06 PM |
This is the script when I fixed it and put your mod in...
while true do wait(2) model = workspace["Buy Dropper1- 200"] if model then workspace["Buy Dropper2- 200"].Parent = game.Lighting if not model then game.Lighting["Buy Dropper2- 200"].Parent = workspace end end end
It doesn't repeat |
|
|
| Report Abuse |
|
|
Yamno
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 123 |
|
|
| 11 May 2016 06:13 PM |
For every instance (parts, models, workspace, lighting, almost everything), you can use :FindFirstChild("name") to check if an object exists as a descendant of that Instance. If it exists, it returns a reference to the object, otherwise it returns nil.
If you wanted to check if "Part" is in Workspace, you would do:
local name = "Part" local model = workspace:FindFirstChild(name) --check under specific location if (model) then --if model exists model:Destroy() --do stuff end
This only works once (does not take multiple "Part", so you need to repeat-until model does not exist), and this assumes that the model will always be a descendant of workspace if it exists.
|
|
|
| Report Abuse |
|
|
|
| 11 May 2016 06:19 PM |
Okay.. So here the script now but how to I make it scan if the "Part" is still there or not over and over until its not there?
model = workspace["Buy Dropper1- 200"] local name = workspace:FindFirstChild("Buy Dropper1- 200") if model then workspace["Buy Dropper2- 200"].Parent = game.Lighting if not model then game.Lighting["Buy Dropper2- 200"].Parent = workspace end end |
|
|
| Report Abuse |
|
|
lululukas
|
  |
| Joined: 23 Aug 2010 |
| Total Posts: 1043 |
|
|
| 11 May 2016 06:29 PM |
| use elseif because if the first if returns false then the second check won't even go through. |
|
|
| Report Abuse |
|
|
Yamno
|
  |
| Joined: 10 Jun 2009 |
| Total Posts: 123 |
|
|
| 11 May 2016 06:57 PM |
firstly, workspace["Buy Dropper1- 200"] is almost the same as workspace:FindFirstChild("Buy Dropper1- 200") so it is redundant to do both.
you can do a repeat-until or a while loop to continually check
------------- repeat-until loop model = workspace:FindFirstChild("Buy Dropper1- 200") --need this to break/stay in the loop
repeat if model then --do stuff end
model = workspace:FindFirstChild("Buy Dropper1- 200") --get the next model or nil wait(.3) --to prevent freezing until (model == nil) --[since model does not exist anymore, do stuff]
------------- while-loop model = workspace:FindFirstChild("Buy Dropper1- 200")--need this to break/stay in the loop
while (model) do --as long as model exists, do stuff --[do stuff] model = workspace:FindFirstChild("Buy Dropper1- 200") -- get next model or nil wait(.3) --to prevent freezing end --[since model does not exist anymore, do stuff] |
|
|
| Report Abuse |
|
|