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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|