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

NPC moving randomly in a restricted area? [closed]

Asked by 4 years ago
Edited 4 years ago

I am making this game where I want NPCs to move randomly in a circular area and I wanted to know if there is a more convenient way to do this than I did? Basically I made a bunch of bricks and used math.random to make the NPC go to a random brick and put those bricks in the circle. I want to know if there is a way to make the NPC move randomly in a constructed circular area and not limited to the points I make.

local NPC = game.Workspace.NPC
local pathdeterminer

while true do
 pathdeterminer = "p" .. math.random(1,6)
    if(pathdeterminer == "p1") then
     NPC.Humanoid:MoveTo(game.Workspace.Points.p1.Position)
     NPC.Humanoid.MoveToFinished:Wait()
    end
    if(pathdeterminer == "p2") then
    NPC.Humanoid:MoveTo(game.Workspace.Points.p2.Position)
    NPC.Humanoid.MoveToFinished:Wait()
    end
    if(pathdeterminer == "p3") then
    NPC.Humanoid:MoveTo(game.Workspace.Points.p3.Position)
    NPC.Humanoid.MoveToFinished:Wait()
    end
    if(pathdeterminer == "p4") then
    NPC.Humanoid:MoveTo(game.Workspace.Points.p4.Position)
    NPC.Humanoid.MoveToFinished:Wait()
    end
    if(pathdeterminer == "p5") then
    NPC.Humanoid:MoveTo(game.Workspace.Points.p3.Position)
    NPC.Humanoid.MoveToFinished:Wait()
    end
    if(pathdeterminer == "p6") then
    NPC.Humanoid:MoveTo(game.Workspace.Points.p4.Position)
    NPC.Humanoid.MoveToFinished:Wait()
    end
    wait(0.5)
end


1
You can use a CFrame instead of a bricks position for MoveTo Benbebop 1049 — 4y
0
So what’s the problem? How can we fix it? raid6n 2196 — 4y
0
There isn't a problem really I just wanted to know if there is a better way to script what I want to do cyanslime123 23 — 4y
1
CFrame would work. raid6n 2196 — 4y

Closed as Primarily Opinion-Based by DeceptiveCaster

This question has been closed because it is a discussion about a topic focused on diverse opinions, which isn't a good fit for our Q&A format.

Why was this question closed?