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

NPC follow script isn't working?-saying "Vector3 expected, got number" when there is a Vector3

Asked by 4 years ago

I'm creating a follow script but it's saying "Vector3 expected, got number" even if there is a Vector3.

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        local enemy = game.Workspace:WaitForChild("Chef")
        wait(1)
        follow = false

        while true do
        if Character.UpperTorso ~= nil then
            if Character.UpperTorso.Position - enemy.Torso.Position.X <= Vector3.new(10,0,0) then
                follow = true
                end
        end

        if follow then
        enemy.Humanoid.WalkToPoint = Character.UpperTorso.Position.X
        end
         wait(0.5)
        end
    end)
end)

2 answers

Log in to vote
0
Answered by 4 years ago
Character.UpperTorso.Position - enemy.Torso.Position.X 

Your trying to subtract a number from a vector3 value so no what u did > Vector3.new(2,2,2) + 4

Ad
Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

WalkToPoint of Humanoid requires a vector3 to walk to. You are giving it the X component of UppterTorso's Position.

To fix this just give it the actual position.

Also you are subtracting a number from a Vector3 position, lets instead subtract the actual position and use .Magnitude to check if it less than 10 studs away.

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        local enemy = game.Workspace:WaitForChild("Chef")
        wait(1)
        follow = false

        while true do
        if Character.UpperTorso ~= nil then
            if (Character.UpperTorso.Position - enemy.Torso.Position).Magnitude <= 10 then
                follow = true
                end
        end

        if follow then
        enemy.Humanoid.WalkToPoint = Character.UpperTorso.Position
        end
         wait(0.5)
        end
    end)
end)

Answer this question