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

Please help me fix this follow script?

Asked by
Xl5Xl5 65
9 years ago

How would I get the NPC to follow the player when Choice4 is selected? Hierarchy of where the script is. NPC>Head>Dialog>My script is here>Choice4

Please can someone help me with this, the NPC doesn't follow when Choice4 is selected. Please help! thanks!

script.Parent.DialogChoiceSelected:connect(function(player,choice)

  local humanoid = player.Character:findFirstChild("Humanoid")

    if not humanoid then return end --End the function if the humanoid isn't found
local stats = player:FindFirstChild('leaderstats')
    if not stats then return end
local rep = stats:FindFirstChild('Reputation')
    if not rep then return end

    if choice.Name == "Choice1" then --If the DialogChoice's name is Die then do the following

        wait(1)
rep.Value = rep.Value - 1       

    elseif choice.Name == "Choice2" then

        wait(1) --Make the player jump. -- humanoid.Jump = true
rep.Value = rep.Value + 1

elseif choice.Name == "Choice3" then

        wait(1)
rep.Value = rep.Value - 2



local pathfinding = game:GetService("PathfindingService")

function getDistanceFrom(part1, part2, distance)
if (part1.Position - part2.Position).magnitude < distance then
return true
end
return false
end

elseif choice.Name == "Choice4" then
while true do
wait(0.8) -- edit this to your desire, this is how much he changes his path
local char = player.Character
local path = pathfinding:ComputeSmoothPathAsync(NPC.Torso.Position, char.Torso.Position)

for i, v in pairs(path:GetPointCoordinates()) do -- forgot the name of that method, could be wrong
NPC.Humanoid:MoveTo(v)
NPC.Humanoid.MoveToFinished:wait()
end

end
end
    end

end)

0
We don't know what choice 4 is or if the script returns an error, which is important information Validark 1580 — 9y

1 answer

Log in to vote
0
Answered by 4 years ago

I suggest using these scripts

If your making an NPC Walk

NOTES: In the NPC you want to move add an IntValue

Name it 'Mode' (must have a capital 'M') and the Value must me '0'

and here is the script for a moving npc

local CurrentPart = nil
local MaxInc = 16

function onTouched(hit)
    if hit.Parent == nil then
        return
    end
    local humanoid = hit.Parent:findFirstChild("Humanoid")

    if humanoid == nil then
        CurrentPart = hit
    end
end

function waitForChild(parent, childName)
    local child = parent:findFirstChild(childName)

    if child then
        return child
    end

    while true do
        print(childName)

        child = parent.ChildAdded:wait()

        if child.Name==childName then
            return child
        end
    end
end

local Figure = script.Parent
local Humanoid = waitForChild(Figure, "Humanoid")
local Torso = waitForChild(Figure, "Torso")
local Left = waitForChild(Figure, "Left Leg")
local Right = waitForChild(Figure, "Right Leg")

Humanoid.Jump = true

Left.Touched:connect(onTouched)
Right.Touched:connect(onTouched)

while true do
    wait(math.random(2, 6))

    if CurrentPart ~= nil then
        if math.random(1, 2) == 1 then
            Humanoid.Jump = true
        end

        Humanoid:MoveTo(Torso.Position + Vector3.new(math.random(-MaxInc, MaxInc), 0, math.random(-MaxInc, MaxInc)), CurrentPart)
    end
end

thats an NPC Script

Ad

Answer this question