--[[ Varibles ]] local NPC = workspace:WaitForChild("Leader") local NPCPosFolder = workspace:WaitForChild("NPCPositions") local CurrentPos = 1 local NextPos = NPCPosFolder["Pos"..CurrentPos].Position local Repstorage = game:GetService("ReplicatedStorage") local Status = Repstorage:WaitForChild("Status") --[[ StoryLine ]] local Dialog = { "Campleader : Heya fokes , Welcome to camp greenlake", "If you follow me i'll show you around" } local function FirstPlayerLoaded() end --[[ function for letting a npc walk ]] --[[ Main StoryLineScript ]] local function PlayStoryLine() Status.Value = Dialog[1] wait(3) Status.Value = Dialog[2] for NpcWalk = 1,2 do NPC.Humanoid:MoveTo(NextPos) NPC.Humanoid.MoveToFinished:wait() CurrentPos = CurrentPos + 1 print(CurrentPos) end end PlayStoryLine()
So bassicly i have this for loop to make my script not so long and hard to manage but it adds current pos twice so it will end up being 3 and it does not move to the second location is has how do i fix this?
Try this:
--[[ Varibles ]] local NPC = workspace:WaitForChild("Leader") local NPCPosFolder = workspace:WaitForChild("NPCPositions") local CurrentPos = 1 local NextPos = NPCPosFolder["Pos"..CurrentPos].Position local Repstorage = game:GetService("ReplicatedStorage") local Status = Repstorage:WaitForChild("Status") --[[ StoryLine ]] local Dialog = { "Campleader : Heya fokes , Welcome to camp greenlake", "If you follow me i'll show you around" } local function FirstPlayerLoaded() end --[[ function for letting an npc walk ]] --[[ Main StoryLineScript ]] local function PlayStoryLine() Status.Value = Dialog[1] wait(3) Status.Value = Dialog[2] NpcWalk = 2 -- How Many Times To Loop repeat NPC.Humanoid:MoveTo(NextPos) NPC.Humanoid.MoveToFinished:Wait() CurrentPos = CurrentPos + 1 print(CurrentPos) until CurrentPos >= NpcWalk end PlayStoryLine()
I think the problem was that you were looping it too fast and it didn't wait right.