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

Why is there a delay in my NPC movement script?

Asked by 6 years ago

In my project, I have a base script that fires a remote event that causes the NPC to begin walking. The only issue is that while it DOES move, it's not when I want. It's around a 2-5 second delay. (i haven't counted i probably should've)

Here is the code.

Base script:

local ShowDialog = game.ReplicatedStorage.ShowDialog
local ShowTinaDialog = game.ReplicatedStorage.ShowTinaDialog
local Opening = game.ReplicatedStorage.Opening
local OpeningWalk = game.ReplicatedStorage.OpeningWalk

--//Waiting for Players
    while true do
        wait(2)
        contestants = {}
        for _, player in pairs(game.Players:GetPlayers()) do
            if player and player.Character then
                local humanoid = player.Character:WaitForChild("Humanoid")
                if humanoid and humanoid.Health > 0 then
                    table.insert (contestants, player)
                end
            end
        end
        if #contestants >= 1 then
            print "We have enough"
            break
        else
            end
    end

--//Table of Team Names (referred to as tribes bc i forgot i was making tdi and not survivor)
local Tribes = { 'Dancing Mice', 'Shouting Wolves', 'Thriller Whales', 'Running Lions', 'Sitting Ducks' }   

--//Setting up Teams
print "Choosing teams."
local team = Instance.new("Team")
team.TeamColor = BrickColor.random()
team.Parent = game:GetService("Teams")
local teamnumberchosen = math.random(5)
team.Name = Tribes[teamnumberchosen]
team.AutoAssignable = false
table.remove(Tribes, (teamnumberchosen))
print "Team one made."

local team = Instance.new("Team")
team.TeamColor = BrickColor.random()
team.Parent = game:GetService("Teams")
local teamnumberchosen = math.random(4)
team.Name = Tribes[teamnumberchosen]
team.AutoAssignable = false
table.remove(Tribes, (teamnumberchosen))
print "Team two made."

--//Opening Sequence
OpeningWalk:FireAllClients()
print "Walking fired."
Opening:FireAllClients()
print "Opening fired."

NPC Movement:

Opening = game:GetService("ReplicatedStorage").OpeningWalk
--//More Variable Thingies
local model = workspace.TinaOpening
local hum = model.Tina.Humanoid

hum.WalkSpeed = 10

--//Make her WALK
local function onOpeningWalk()
    print "Starting to walk"
        hum:MoveTo(model.PointA.Position)
        hum.MoveToFinished:Wait()
        hum:MoveTo(model.PointB.Position)
        hum.MoveToFinished:Wait()
        hum:MoveTo(model.PointC.Position)
        hum.MoveToFinished:Wait()
        hum:MoveTo(model.PointD.Position)
        hum.MoveToFinished:Wait()
        hum:MoveTo(model.PointE.Position)
        hum.MoveToFinished:Wait()
        print "Done walking."
end

Opening.OnClientEvent:connect(onOpeningWalk)

0
In your NPC Movement script, your local function onOpeningWalk(). You haven't specified the number of seconds you want to wait. Without filling it in, ROBLOX will load the next path when everything is finished. I think you should force it by adding a number in the wait(). 0.2 is fine if you don't want a delay. Jxemes 75 — 6y
0
Can you add an example? Because doing hum.MoveToFinished:Wait(0.2) didn't fix it. and adding it in the onOpeningWalk(0.2) made it not run at all. BouncingBrenda 44 — 6y

Answer this question