awiton
|
  |
| Joined: 27 Apr 2012 |
| Total Posts: 2656 |
|
|
| 20 May 2017 11:38 AM |
local NPC = game.Workspace:FindFirstChild(script.Parent.Name)
while true do
wait() if script.Parent.Job.Value == "Lumberjack" then local trees = game.workspace.Map:GetChildren() for i = 1 ,#trees do local tree = trees:findFirstChild("Tree") if tree ~= nil and tree[i]:FindFirstChild("Trunk")~= nil and (tree[i].Trunk.Position - script.Parent.Torso.Position).Magnitude < 100 then NPC.Humanoid:MoveTo(tree[i].Trunk.Position) NPC.Humanoid.MoveToFinished:wait() else wait(4) game.Lighting.CantFindTrees:Clone().Parent = script.Parent.Head script.Parent.Head.CantFindTrees.ConversationDistance = 25 wait(0) end end end end
================================================================================= My output thingy says
"Line 9 - attempt to index a nil value" something/ |
|
|
| Report Abuse |
|
|
|
| 20 May 2017 11:41 AM |
It was unable to find the Tree where you were looking.
|
|
|
| Report Abuse |
|
|
|
| 20 May 2017 11:43 AM |
this code is rhetarded in so many ways, brb rewriting
|
|
|
| Report Abuse |
|
|
awiton
|
  |
| Joined: 27 Apr 2012 |
| Total Posts: 2656 |
|
|
| 20 May 2017 11:47 AM |
| local tree = trees:findFirstChild("Tree") |
|
|
| Report Abuse |
|
|
|
| 20 May 2017 11:49 AM |
This could be written better but I honestly wanted to die inside as I got close to the end of it
local NPC = game.Workspace:FindFirstChild(script.Parent.Name) local hum = NPC:FindFirstChild("Humanoid")
while true do local foundTree wait() if script.Parent.Job.Value == "Lumberjack" then local trees = workspace.Map:GetChildren() for _, v in pairs(workspace.Map:GetChildren()) do if v.Name == "Tree" and v:FindFirstChild("Trunk") and (v:FindFirstChild("Trunk").Position -script.Parent:FindFirstChild("HumanoidRootPart").Position).Magnitude < 100 then hum:MoveTo(v:FindFirstChild("Trunk").Position) hum.MoveToFinished:wait() print("found tree") foundTree = true break end end end if not foundTree then wait(4) local thingy = game.Lighting:FindFirstChild("CantFindTrees"):Clone().Parent = script.Parent:FindFirstChild("Head") thingy.ConversationDistance = 25 end end
|
|
|
| Report Abuse |
|
|
awiton
|
  |
| Joined: 27 Apr 2012 |
| Total Posts: 2656 |
|
|
| 20 May 2017 12:09 PM |
| YES IT WORKS!!!! THANKS SO MUCH!!! My game is one step closer to completion!!! Thank you so much i've been spending hours trying to figure out how to solve it. ya did it! |
|
|
| Report Abuse |
|
|
|
| 20 May 2017 12:12 PM |
you need to work on the logical processing in your code. That thing was a mess. If you get to that stage again just do ctrl+a then press backspace. It's better to work from scratch then try to fix something that you can't work with. Sadly that's how coding works. If it's baroque. Get rid of it. kek.
|
|
|
| Report Abuse |
|
|
awiton
|
  |
| Joined: 27 Apr 2012 |
| Total Posts: 2656 |
|
|
| 20 May 2017 02:12 PM |
Here's my game i'm working on. if ANYONE wants to visit it.
Please don't dislike its work in progress. :) |
|
|
| Report Abuse |
|
|