I'm making a RPG game and I don't know how to make an enemy NPC that follow and kill players. If have anyone know that, please help me. I have try to run this script in Roblox Studio but it not do anything. This is my script code I don't know how to fix it:
01 | players = nil ; --Where we are going to store all the players |
02 | dummy = game.Workspace.Dummy; --Dummy reference |
03 | currentPlayerFollowing = nil ; --The current player the zombie is following |
04 | damage = 2 ; --Change this for more damage if you want |
05 |
06 | function touched(hit) |
07 | --pcall allows for errors to be disregarded so you don't have to worry about random output errors |
08 | if pcall ( function () if hit.Parent.Humanoid ~ = nil then end end ) then --If the character's health storage is there |
09 | pcall ( function () hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage end ); --Do damage |
10 | end |
11 | end |
12 |
13 | dummy.Torso.Touched:connect(touched); |
14 |
15 | while wait( 1 ) do --Forever loop |
What happend with this? Please help me! Thank for your help.
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?
Try this:
01 | local larm = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
02 | local rarm = script.Parent:FindFirstChild( "HumanoidRootPart" ) |
03 |
04 | function findNearestTorso(pos) |
05 | local list = game.Workspace:children() |
06 | local torso = nil |
07 | local dist = 45 |
08 | local temp = nil |
09 | local human = nil |
10 | local temp 2 = nil |
11 | for x = 1 , #list do |
12 | temp 2 = list [ x ] |
13 | if (temp 2. className = = "Model" ) and (temp 2 ~ = script.Parent) then |
14 | temp = temp 2 :findFirstChild( "HumanoidRootPart" ) |
15 | human = temp 2 :findFirstChild( "Humanoid" ) |
local dist = 45 --Change the number to the amount of studs the player has to be for the enemy to start chasing!
I'm assuming the enemy humanoid is named (Zombie) If it isn't go to line 34 and cahge Zombie to whatever the humanoid name is.
Hope this helps!