Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to clone an npc to workspace in a specific position?

Asked by 8 years ago

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

0
X is only made once, put the math.random inside the while loop or something theCJarmy7 1293 — 8y
0
Link a variable to the clone, the line of code below it may be referring to the NPC/Enemy inside of the Mobs rather then the cloned. AshRPG12 42 — 8y

3 answers

Log in to vote
0
Answered by
brianush1 235 Moderation Voter
8 years ago

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
Ad
Log in to vote
0
Answered by 8 years ago

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

Log in to vote
-3
Answered by 8 years ago

Um, how about this: n = Mobs['A.I.M. Melee Soldier']:Clone() .Parent = game.Workspace n.Torso.Position = Vector3.new(putapositionhere, putapositionhere, putapositionhere)

Answer this question