|
| 18 Mar 2015 11:16 PM |
Im trying to make a script that is there is more than 1 of the model it removes it(For starters) this is what i got so far but it does not seem to work.
if game.Workspace["Polar Bear"] > 1 then do game.Workspace["Polar Bear"]:remove() end
|
|
|
| Report Abuse |
|
|
Laedere
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 18 Mar 2015 11:21 PM |
| game.Workspace["Polar Bear"] is not a number value |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 11:22 PM |
| Yes, but i want it so if there is More than 1 it will remove. So how would i set this up? |
|
|
| Report Abuse |
|
|
LuaJake
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2009 |
|
|
| 18 Mar 2015 11:33 PM |
for _, object in pairs(workspace:GetChildren()) do if object.Name == "Polar Bear" then object:Destroy() end end |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 11:35 PM |
| I ran that didnt work, i want it to go in the Workspace(The Script) so it can remove other as well but that didnt seem to work either |
|
|
| Report Abuse |
|
|
LuaJake
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2009 |
|
|
| 18 Mar 2015 11:36 PM |
You'll need to go into more detail, I made a script according to the information you supplied me:
Remove all objects in Workspace named Polar Bear. |
|
|
| Report Abuse |
|
|
|
| 18 Mar 2015 11:41 PM |
| But i want it to remove a certain amount I pmed you |
|
|
| Report Abuse |
|
|
LuaJake
|
  |
| Joined: 20 Jun 2013 |
| Total Posts: 2009 |
|
|
| 19 Mar 2015 01:20 AM |
Alright, use this:
local wantToRemove = 20 -- change 20 to the amount you want to remove for i = 1,wantToRemove do local obj = workspace:FindFirstChild('Polar Bear') if obj ~= nil then obj:Destroy() else print('Does not exist!') end end
LuaJake - ROBLOX Developer - R$261 - Tx1,426 |
|
|
| Report Abuse |
|
|
Luminak
|
  |
| Joined: 27 May 2012 |
| Total Posts: 2809 |
|
| |
|
|
| 19 Mar 2015 11:09 AM |
| But what about Having it remove if there is more than (2) |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 11:14 AM |
| Let me help you, hold on a minute |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 11:21 AM |
Please explain what you are trying to do? Why would there be two of them? |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 11:22 AM |
local MaxPolarBears = 10 local PolarBears
for num, name in pairs(game.Workspace:GetChildren()) do is name.Name == "Polar Bear" then table.insert(PolarBears,name) end end
print("There are "..#PolarBears.." Polar Bears currently!") if #PolarBears<=MaxPolarBears then print("Not over limit!") return end for i = 1, #PolarBears-MaxPolarBears do table.remove(PolarBears,math.random(1,#PolarBears)) end
There. It counts the number of models named "Polar Bear" in workspace, and if the amount is greater than the max allowed, it randomly chooses the amount of Polar Bears over the limit to be removed. |
|
|
| Report Abuse |
|
|
Roblok1
|
  |
| Joined: 27 Jul 2011 |
| Total Posts: 2019 |
|
|
| 19 Mar 2015 11:55 AM |
Here let me help. I assume it's not just polar bears u want to check. So I did this:
-- this will check every object in the workspace and remove it if there is more than one object with that name
items = workspace:children() workspace.ChildAdded:connect(function(child) for _,i in pairs(items)do if i.Name == child.Name then child:Destroy() end end items = workspace:children() end) |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 12:00 PM |
| @bloo didnt seem to work i think you have a script error, with name |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 12:00 PM |
| and basicaly i want it so that if there is lets say 20 polar bears it will remove some |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 12:08 PM |
| The PolarBear spawn Because its a survival game when its winter, So lets say to many spawn So 20 of them it removes some and the Model name is "PolarBear" |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 12:31 PM |
a top notch survival game and you don't know how to do this?
making survival games is a tough chore to do |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 12:41 PM |
| Well I wouldn't say as much survival, it spawns Models, animals. with animations i have most of everything, So yes i do no what i'm doing but i'm working on a clean up system which i am not familiar with, i mainly work on GUI's not this |
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 19 Mar 2015 12:43 PM |
| If you are spawning them, why don't you just increase an int value by one everytime you spawn a polar bear, and check to see if that number is below 20 before you spawn a new one. Then, whenever a polar bear is killed, a script subtracts 1 from the int value. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 01:07 PM |
But see that's just my point i cant seem to get it to work, hense i rather just do it the way where if there is more than 20 and lets say there is 40 remove 20. But everyone except bloo has written something different but bloos does not seem to work. |
|
|
| Report Abuse |
|
|
Tynezz
|
  |
| Joined: 28 Apr 2014 |
| Total Posts: 4945 |
|
|
| 19 Mar 2015 02:14 PM |
function GetNumber(name,parent) local objects={} for i,v in pairs(parent:GetChildren()) do if v.Name==name then table.insert(objects,v end end return objects end if #GetNumber(["Polar Bear"],game.Workspace)>1 then for i,v in pairs(GetNumber(["Polar Bear"],game.Workspace)) do v:Destroy() end end |
|
|
| Report Abuse |
|
|
Luminak
|
  |
| Joined: 27 May 2012 |
| Total Posts: 2809 |
|
|
| 19 Mar 2015 04:03 PM |
OK SO 1 = game.Workspace.Part1 2 = game.Workspace.Part2 wait(1) 1:Destory() 2:Destroy() |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 08:17 PM |
| Thanks All of you guys for your help problem solved :) thanks to bloo all of you thanks for your help. |
|
|
| Report Abuse |
|
|
|
| 19 Mar 2015 09:16 PM |
Im sorry I couldnt help but crack up at the starting script. Im not usually mean. |
|
|
| Report Abuse |
|
|