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

Can someone help me with teleporting NPCs to a map?

I tried using math.random(), but i got a error message, here's the code I used:

local CTorso = Clone:FindFirstChild("UpperTorso") or Clone:FindFirstChild("Torso")
		if Map:FindFirstChild("Min") and Map:FindFirstChild("Max") then
			local Min = Map:FindFirstChild("Min")
			local Max  =Map:FindFirstChild("Max")
			CTorso.CFrame = CFrame.new(math.random(Max.Position.X,Min.Position.X), math.random(Max.Position.Y,Min.Position.Y)+5,math.random(Max.Position.Z,Min.Position.Z))
		else
			error("Min/Max Is Missing From Map")
			break
		end

here's the error message I got Can anyone help me?

4 comments

0

I forgot to mention that it works perfectly in studio

0

Where is the NPC located? I reccomend ReplicatedStorage or ServerStorage

0

Also, do you want the NPC to spawn in a random location or just 1 location?

0

@zboi i want the npc to spawn in a random location with a certain set of coords represented with two parts, min and max. the distance between those two parts represents the possibilities

1 answer

Add this to the top of your script.


Max = 150.Studs.Length
Min = 25.Studs.Length

local CTorso = Clone:FindFirstChild("UpperTorso")


1 comment

0

smacks head really hard u cant just do that 1st its to short and 2nd u didn't explain why.

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