I'm trying to make a script, which is in workspace, to clone an npc to the position of any parts name "Tele"followed by random number from 1 to 10. (Ex: Tele1, Tele10). What this script basically does is spawn enemy npcs or mobs. Just got back to Roblox and am a bit rusty. Still a beginner at scripting, but I would appreciate your help. Thanks
Mobs = game.ReplicatedStorage.Mobs X = math.random(10) while wait() do c = math.random(1,5) if c == 1 then Mobs["A.I.M. Melee Soldier"]:clone().Parent = game.Workspace Mobs["A.I.M. Melee Soldier"].Torso.CFrame = workspace["Tele" .. X].CFrame + Vector3.new(0, 10, 0) end end
You forgot to access the clone, and you're attempting to add CFrame + Vector3! Also, this would spawn NPCs pretty fast... I don't know if that's what you want, so I'll just leave it. Here's the fixed code:
Mobs = game.ReplicatedStorage.Mobs X = math.random(10) while wait() do c = math.random(1,5) if c == 1 then local Clone = Mobs["A.I.M. Melee Soldier"]:clone() Clone.Parent = game.Workspace Clone.Torso.CFrame = workspace["Tele" .. X].CFrame * CFrame.new(0, 10, 0)--Vector3.new(0, 10, 0) end end
First, find the position of parts called "Tele<Random number>" Then set the Vector3 positioning (Use Vector3.new(X,Y,Z) )of the NPC to the position of the "Tele" part (Increase the Y axis a bit so the NPC doesn't spawn inside the part).
Um, how about this: n = Mobs['A.I.M. Melee Soldier']:Clone() .Parent = game.Workspace n.Torso.Position = Vector3.new(putapositionhere, putapositionhere, putapositionhere)