generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Simple script problem - Searching for base

Previous Thread :: Next Thread 
randomguy99 is not online. randomguy99
Joined: 21 Jul 2008
Total Posts: 4241
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 is not online. 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
randomguy99 is not online. randomguy99
Joined: 21 Jul 2008
Total Posts: 4241
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 is not online. 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
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
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
ShipSinker3 is not online. ShipSinker3
Joined: 07 Oct 2009
Total Posts: 158
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 is not online. 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
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
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 is not online. 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
AdvorsusDuo is not online. AdvorsusDuo
Joined: 17 May 2012
Total Posts: 5265
15 Jul 2012 02:07 PM
oh sorry thought you were talking to me

-Nick
Report Abuse
lordyoman is not online. lordyoman
Joined: 10 Jun 2010
Total Posts: 426
15 Jul 2012 02:08 PM
^ But you posted after me?...
Report Abuse
randomguy99 is not online. randomguy99
Joined: 21 Jul 2008
Total Posts: 4241
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
thesims2and3 is not online. thesims2and3
Joined: 13 Jun 2009
Total Posts: 140
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
TheEpicSamuri is not online. TheEpicSamuri
Joined: 04 Dec 2011
Total Posts: 1343
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
thesims2and3 is not online. thesims2and3
Joined: 13 Jun 2009
Total Posts: 140
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
thesims2and3 is not online. thesims2and3
Joined: 13 Jun 2009
Total Posts: 140
15 Jul 2012 05:11 PM
print 'hello' Does work but i prefer to use print ("hello")
Report Abuse
Drak0Master is not online. Drak0Master
Joined: 10 Aug 2009
Total Posts: 836
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image