Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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
		

2 comments

0

X is only made once, put the math.random inside the while loop or something

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.

3 answers

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.