generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: NPC unable to follow after player is dead and re spawned.

Previous Thread :: Next Thread 
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 01:43 PM
Coming back to scripting after a few months. I have redesigned my old NPC script (Which is broken). Tried to fix it this time so I simplified it and shortened it.

What works:
NPC is able to follow a player once touched

What is broken:
After the player is dead and re touches the NPC it will not follow as it did previous. It will A walk randomly (As if it was looking for the old Torso) or B not move at all.

This is my best guess.

What Im asking for:
Asking for a way to fix the problem that is broken :) (Feel free to roast my horrible layed out scripts)

for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then -- If V is a part that can be touched then
v.Touched:connect(function(player_hit,attacking)
if player_hit.Parent:FindFirstChild("Humanoid") and player_hit.Parent:FindFirstChild("Humanoid").Health > 0 and script.Parent.Monster.Health > 0 then -- If player_hit is a player and Monster is still alive
########################################################################################################################### wait(.1)
end

while attacking == true do
wait(5)
attacking = false
end

else do
print "The object hit is not a player" -- This is not a player
end
end
end)
end
end
Report Abuse
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 01:45 PM
damage = script.Parent:WaitForChild("Stats"):WaitForChild("Damage").Value
health = script.Parent:WaitForChild("Stats"):WaitForChild("Monster_Health").Value
regen_time = script.Parent:WaitForChild("Stats"):WaitForChild("Regen_Time").Value
attack_sound = script.Parent:WaitForChild("Sounds"):WaitForChild("Attack_Sound")
script.Parent.Monster.HealthDisplayDistance = health
script.Parent.Monster.MaxHealth = health
script.Parent.Monster.Health = health

for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:connect(function(player_hit,attacking)
if player_hit.Parent:FindFirstChild("Humanoid") and player_hit.Parent:FindFirstChild("Humanoid").Health > 0 and script.Parent.Monster.Health > 0 then
attacking = true
while attacking == true do
script.Parent.Monster:MoveTo(player_hit.Parent.Torso.Position)
wait(.1)
end

while attacking == true do
wait(5)
attacking = false
end

else do
print "The object hit is not a player" -- This is not a player
end
end
end)
end
end
Report Abuse
Monadic is not online. Monadic
Joined: 03 Aug 2016
Total Posts: 731
17 Sep 2016 01:46 PM
SPAM! SPAM! SPAM! TALKING! TALKING!
POST!
Report Abuse
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 01:46 PM
Apparently first code got censored out. Also "Monster" is Humanoid just renamed as I have learned no other better detection way for swords. (If I only want people to be able to attack monsters not people)
Report Abuse
Monadic is not online. Monadic
Joined: 03 Aug 2016
Total Posts: 731
17 Sep 2016 01:47 PM
Rawr!
That's a monster noise.
Report Abuse
heaveheaver is not online. heaveheaver
Joined: 09 Jul 2012
Total Posts: 2662
17 Sep 2016 01:50 PM
Does it give you an error in the output though?


~Heave will beheave.
Report Abuse
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 01:52 PM
No errors in the Output.
Report Abuse
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 02:06 PM
Possible Fix. I remember about magnitude. I will use that if a player is within the area it will follow and when its out it will return to its previous spot, hopefully using the inbuilt pathfinding.
Report Abuse
Alfa247 is not online. Alfa247
Joined: 15 Jan 2010
Total Posts: 118
17 Sep 2016 02:24 PM
All fixed.

(To those who have googled and found this)

Instead of making the NPC follow the player after they touch them ingame. I used magnitude to detect how far away they are from the NPC. If they were within 10 Studs the NPC would walk to the player.

(Have not tested it with multiple players)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image