|
| 15 Jul 2012 01:44 PM |
I'm trying to make a script that searches for a base in workspace. Problem is, I don't know how.
if game.Workspace.Base = nil then print 'oh noes' else print 'all is good'
The error is that it's expecting 'then' near =. Please help? |
|
|
| Report Abuse |
|
|
lordyoman
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 426 |
|
|
| 15 Jul 2012 01:46 PM |
if game.Workspace.Base == nil then print(oh noes) else print(all is good) end |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 01:52 PM |
@lord One problem. Instead of printing anything, it just says "Base is not a valid member of workspace." |
|
|
| Report Abuse |
|
|
lordyoman
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 426 |
|
|
| 15 Jul 2012 01:56 PM |
a = game.Workspace:GetChildren()
for i=1,#a do if a[i].Name == "Base" then print(Ok) else print(Oh no!) end end
Im not sure try this... |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 01:56 PM |
local base = Workspace:FindFirstChild("Base") if base then print 'all is good' else print 'oh noes' end
-Nick |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 01:57 PM |
| for starters, as your using 'if' you must use == not = to find it. As for your other question, make sure 'Base' is in workspace. |
|
|
| Report Abuse |
|
|
lordyoman
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 426 |
|
|
| 15 Jul 2012 01:58 PM |
| ^ Yes, But he needs the script to work with no base in the workspace to! |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 02:04 PM |
@lordyoman
That's what the "else" is for.
else means if ANYTHING AT ALL goes unaccording to the script, then something else will happen |
|
|
| Report Abuse |
|
|
lordyoman
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 426 |
|
|
| 15 Jul 2012 02:06 PM |
| ^ I'm just saying he said "make sure base is in the workspace"... It shouldn't matter... |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 02:07 PM |
oh sorry thought you were talking to me
-Nick |
|
|
| Report Abuse |
|
|
lordyoman
|
  |
| Joined: 10 Jun 2010 |
| Total Posts: 426 |
|
|
| 15 Jul 2012 02:08 PM |
| ^ But you posted after me?... |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 03:06 PM |
Ok, I've developed this script.
while true do a = game.Workspace:GetChildren()
for i=1,#a do if a[i].Name == "Base" then print 'Scan done. Baseplate present.' else print 'Scan done. Baseplate not found. Making new baseplate.' b = Instance.new("Part") b.Name = "Base" b.Anchored = true b.BrickColor = BrickColor.new(37) b.Size = Vector3.new(512, 1, 512) b.Parent = game.Workspace print 'Baseplate made.' wait(30) end end end
The problem with this one is that it creates a new baseplate no matter else. How could I fix this? |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 04:50 PM |
Until now I made this work:
a = Game.workspace.Base
if a.Name == "Base" then print("Scan done. Baseplate present.") else print("Scan done. Baseplate not found. Making new baseplate.") b = Instance.new("Part") b.Name = "Base" b.Anchored = true b.BrickColor = BrickColor.new(37) b.Size = Vector3.new(512, 1, 512) b.Parent = game.Workspace print ("Baseplate made.") wait(30) end
|
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 05:05 PM |
if game.Workspace.Base == nil then print("oh noes") else print("all is good") end
------
I think when you print you have to say print("oh noes")
Instead of
print('oh noes') |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 05:09 PM |
You can also use this:
a = game.Workspace:GetChildren() for i=1,#a do if a[i].Name == "Base" then print("Scan done. Baseplate present.") elseif script.Parent:FindFirstChild("Base") == nil then --Replace script.Parent:FindFirstChild("Base") with Game.workspace:FindFirstChild("Base") if you move the script intro another location than Game.workspace print("Scan done. Baseplate not found. Making new baseplate.") b = Instance.new("Part") b.Name = "Base" b.Anchored = true b.BrickColor = BrickColor.new(37) b.Size = Vector3.new(512, 1, 512) b.Parent = game.Workspace print 'Baseplate made.' wait(30) end end
|
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 05:11 PM |
| print 'hello' Does work but i prefer to use print ("hello") |
|
|
| Report Abuse |
|
|
|
| 15 Jul 2012 05:44 PM |
Easiest and most convenient script, here for you.
search = "Base" subject = game.Workspace replace = true local item = subject[search] if item ~= nil then print(search.." has been located in "..subject.Name..".") else if replace == true then
-- Replace this with whatever you want to inject, replacing the search.
replacement = Instance.new("Part", subject) replacement.Name = search replacement.Size = Vector3.new(500, 0.4, 500) replacement.TopSurface = "Smooth" replacement.BottomSurface = "Smooth" replacement.Anchored = true replacement.Locked = true replacement.BrickColor = BrickColor3.new("Camo")
print(search.." was not found and has been replaced!") else print("search.." was not found, no action has taken place.) end end |
|
|
| Report Abuse |
|
|