|
| 20 Jul 2014 04:23 PM |
I've been trying to get this function to work, but the if statements aren't firing. BotScript is in ServerScriptService and Robot is in the Robots model, so it should be working fine. I'm really not sure what's wrong:
_G["RobotBuilding"] = function(BotScript,Robot)
print(BotScript.Parent.Name) -- ServerScriptService print(Robot.Parent.Name) -- Robots
if game.ServerScriptService:FindFirstChild(BotScript) then print("FoundScript") -- Doesn't print end if game.Workspace.Lobby.Robots:FindFirstChild(Robot) then print("FoundRobot") -- Doesn't print end
end
I've only just started to use Global functions, so I'm assuming it has something to do with that? |
|
|
| Report Abuse |
|
|
Tynexx
|
  |
| Joined: 11 Jul 2012 |
| Total Posts: 1559 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 20 Jul 2014 04:25 PM |
| It's working fine, but looking at your script it appears BotScript isn't a string but an object. |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 20 Jul 2014 04:27 PM |
^ This. FindFirstChild requires a string. Also, in your declaration of the global function, the brackets and quotes aren't necessary. |
|
|
| Report Abuse |
|
|
| |
|
Krypticon
|
  |
| Joined: 12 Feb 2014 |
| Total Posts: 680 |
|
|
| 20 Jul 2014 04:43 PM |
| @blockoo FindFirstChild doesn't require a string :) |
|
|
| Report Abuse |
|
|
| |
|
Krypticon
|
  |
| Joined: 12 Feb 2014 |
| Total Posts: 680 |
|
|
| 21 Jul 2014 01:04 PM |
I use FindFirstChild without a string regularly though, like:
local players=Game.Players:GetPlayers() local selected=players[math.random(1,#players)) local target=Game.Workspace:FindFirstChild(selected.Name)
etc.
And btw, I know the code is ineffective, it's purely an example I made of the top of my head. :) |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 21 Jul 2014 04:25 PM |
| That's still using a string. selected.Name is a string. |
|
|
| Report Abuse |
|
|
|
| 21 Jul 2014 04:28 PM |
| where is this script ?? is it in serverscriptstorage ?? then dont do game.ServerScriptService use script.Parent if the script is somewhere else then u cant find anything that is in serverscriptstorage because its locked other scripts cant see it |
|
|
| Report Abuse |
|
|