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 » Scripters
Home Search
 

Re: If statement

Previous Thread :: Next Thread 
xsuttreex is online. xsuttreex
Joined: 07 Sep 2009
Total Posts: 97
27 Nov 2015 06:28 PM
How do you make something occur with an if statement based on whether something exists somewhere, such as the workspace?
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
27 Nov 2015 06:30 PM
if object then
-- code
end

If the object doesn't exist, then it will be nil, and conditional statements interpret "nil" as "false".
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
27 Nov 2015 06:31 PM
Lets say that there is something named

'Hot_Dragon_480p_2015' in the workspace
I could do something like this

if workspace:FindFirstChild'Hot_Dragon_480p_2015' then print'yiss' end

now lets also say that you plan on interacting with this item (which is usually the case) it is more efficient to do this instead

local A = workspace:FindFirstChild'Hot_Dragon_480p_2015'
if A then print(A.Name) end

( ͡° ͜ʖ ͡°)
Report Abuse
xsuttreex is online. xsuttreex
Joined: 07 Sep 2009
Total Posts: 97
27 Nov 2015 06:32 PM
Alright. Can you tell me why this doesn't work?

main script (name of the script):

tsu = game.ServerStorage.Tsunami
tsu.Parent = game.Workspace
tsu.CanCollide = false
tsu.Position = Vector3.new(0,-107.13,-889.51)
if tsu.Position == Vector3.new(0,-21.13,-975.51) then
workspace["first cframe script"]:Remove()
while true do
tsu.CFrame = tsu.CFrame * CFrame.new(0,-1.5,-1)
wait(.1)
end
end

first cframe script (name of the script):

if game.Workspace.Tsunami then
while true do
tsu = workspace.Tsunami
tsu.CFrame = CFrame.new(0,1,-1)
wait(.1)
end
end
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
27 Nov 2015 06:35 PM
:v before autoamtically assuming every item is going to exist, you should use if statements if not the :WaitForChild method

waitforchild allows you to yield the thread until that item exists and is returned, so I'd suggest using that before interacting with objects kthx
Report Abuse
magicalandre13 is not online. magicalandre13
Joined: 21 Jan 2011
Total Posts: 5327
27 Nov 2015 06:42 PM
for i,v in pairs(game.Workspace:GetChildren())do
if v.Name == "Something" then
print("i gotchu brooo")
end
end
Report Abuse
mycheeze is not online. mycheeze
Joined: 27 Jun 2011
Total Posts: 6748
27 Nov 2015 06:48 PM
k, clearly I overestimated my fellow scripter's abilities to fulfill the goal at hand, I was wrong.

local T = game:GetService'ServerStorage':WaitForChild'Tsunami'
print'Tsunami found'

T.Parent, T.CanCollide, T.Position = workspace, false, Vector3.new(0, -107.13, -889.51) if T.Position == Vector3.new(0, -21.13, -975.51) then workspace:WaitForChild'first cframe script':Destroy() while wait(.1) do T.CFrame = T.CFrame * CFrame.new(0, -1.5, -1) end end local T = workspace:WaitForChild'Tsunami' while wait(.1) do T.CFrame = CFrame.new(0, 1, -1) end

Like how hard is it to use the :FindFirstChild and :WaitForChild method I told you about >:V
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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