ForeverDev

Untitled

Oct 1st, 2014
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. --[[ local script in StarterGui.  This handles the creation of a new AI.  NewAI is a remote function located inside 'GameControl', a model in Workspace.  All of this works perfectly fine in Play Solo mode.  
  2.  
  3. NOTE: The error is "ai is a nil value"
  4.  
  5. ]]
  6.  
  7. local player = game.Players.LocalPlayer
  8. local mouse = player:GetMouse()
  9. local controls = Workspace.GameControl
  10.  
  11. function hookUpEvents(ai)
  12.     local human = ai:FindFirstChild("Humanoid")
  13.     if human then
  14.         mouse.Button1Down:connect(function()
  15.             human:MoveTo(mouse.Hit.p or human.Parent.Torso.Position)
  16.         end)
  17.     end
  18. end
  19.  
  20. local event;
  21. event = mouse.KeyDown:connect(function(key)
  22.     if key:lower() == "k" then
  23.         local ai = controls.NewAI:InvokeServer("Tester")
  24.         ai.Parent = Workspace
  25.         ai.Name = player.Name .. "'s AI"
  26.         ai:MakeJoints()
  27.        
  28.         local weld = Instance.new("Weld", ai.Torso)
  29.         weld.Part0 = ai.Torso
  30.         weld.Part1 = ai.HumanoidRootPart
  31.        
  32.         hookUpEvents(ai)
  33.        
  34.         event:disconnect()
  35.     end
  36. end)
  37.  
  38.  
  39.  
  40.  
  41. --this is the remote event in the Workspace.  It returns a new cloned AI.  The AIs are located inside a model in ServerStorage
  42.  
  43. script.Parent.NewAI.OnServerInvoke = function(player, class)
  44.     return game.ServerStorage.NPC[class]:clone()
  45. end
Advertisement
Add Comment
Please, Sign In to add comment