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
|
  |
| 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
|
  |
| Joined: 03 Aug 2016 |
| Total Posts: 731 |
|
|
| 17 Sep 2016 01:46 PM |
SPAM! SPAM! SPAM! TALKING! TALKING! POST! |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 03 Aug 2016 |
| Total Posts: 731 |
|
|
| 17 Sep 2016 01:47 PM |
Rawr! That's a monster noise. |
|
|
| Report Abuse |
|
|
|
| 17 Sep 2016 01:50 PM |
Does it give you an error in the output though?
~Heave will beheave. |
|
|
| Report Abuse |
|
|
Alfa247
|
  |
| Joined: 15 Jan 2010 |
| Total Posts: 118 |
|
| |
|
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
|
  |
| 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 |
|
|