Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ 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.
- NOTE: The error is "ai is a nil value"
- ]]
- local player = game.Players.LocalPlayer
- local mouse = player:GetMouse()
- local controls = Workspace.GameControl
- function hookUpEvents(ai)
- local human = ai:FindFirstChild("Humanoid")
- if human then
- mouse.Button1Down:connect(function()
- human:MoveTo(mouse.Hit.p or human.Parent.Torso.Position)
- end)
- end
- end
- local event;
- event = mouse.KeyDown:connect(function(key)
- if key:lower() == "k" then
- local ai = controls.NewAI:InvokeServer("Tester")
- ai.Parent = Workspace
- ai.Name = player.Name .. "'s AI"
- ai:MakeJoints()
- local weld = Instance.new("Weld", ai.Torso)
- weld.Part0 = ai.Torso
- weld.Part1 = ai.HumanoidRootPart
- hookUpEvents(ai)
- event:disconnect()
- end
- end)
- --this is the remote event in the Workspace. It returns a new cloned AI. The AIs are located inside a model in ServerStorage
- script.Parent.NewAI.OnServerInvoke = function(player, class)
- return game.ServerStorage.NPC[class]:clone()
- end
Advertisement
Add Comment
Please, Sign In to add comment