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

How can I make the Enemy Humanoid act like an NPC and follow the player? [closed]

Asked by 4 years ago

So I just wrapped up and polished a gun script, then I went to create NPC's. These NPC's have a Humanoid named "EnemyHum". This way, player's can't kill each other.

I also want to add a feature where the glass humanoids will follow you and try to kill you with their melee weapons.

I'm not asking for any scripts, but does anyone have something that might help? Please provide some examples so I understand.

Thank you for reading! I hope I get a good answer on this post!

Closed as Not Constructive by Gojinhan and DeceptiveCaster

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 4 years ago

There is a function in Instance Humanoid called MoveTo where the first argument is the vector3 value for the end point of where the enemy NPC will follow. Please note, you can use https://developer.roblox.com/en-us to find some descriptions for Instances, their properties, their functions and Events.

Ad
Log in to vote
0
Answered by 4 years ago

here's my follow script, you might need to make a few modifications to make it fit your specific scenario, but I hope it gives you a better idea of in which to go.

local hRP = script.Parent.HumanoidRootPart
local h = script.Parent.Humanoid    
local spawnCF = script.Parent.HumanoidRootPart.CFrame

function findPlayer()
    for _,v in next,game.Players:GetPlayers()do
        if v.Character then
            local char = v.Character
            if char:FindFirstChild("Humanoid") then
                local ptorso = char.HumanoidRootPart
                if(ptorso.Position-hRP.Position).magnitude <= 30 then
                    return v

                end
            end
        end
    end
    return nil
end
while wait() do
    local player = findPlayer()
    if player ~= nil then
        h:MoveTo(player.Character.HumanoidRootPart.Position)
    else 
        h:MoveTo(spawnCF.Position)
    end
end