I need to assistance achieving an NPC to walk to each plot, and harvest in a timely manner.
The issue is, the NPC walks to sometimes 4 instead of all 6 plots needing harvested
Solutions tried include, adding Debounce, and adding wait( )'s to slow/enhance the harvesting process.
I have tried adding 2 NPC’s to enhance the harvest, although they both seem to go after the same 4 plots, nonetheless jumble around haphazardly.
-- Variables
local humanoid = script.Parent.Humanoid
local soil = game.Workspace.Soils:GetChildren()
local rest = game.Workspace.RestingPosition
local db = true
-- Functions
-- Script Logic
for _, G in ipairs(soil) do
G.GrownValue:GetPropertyChangedSignal("Value"):Connect(function()
while db do
task.wait(3)
if G.GrownValue.Value == true then
db = true
task.wait(1)
print("Moved")
script.Parent.Humanoid:MoveTo(G.Position)
elseif G.GrownValue.Value == false then
db = false
task.wait(1)
script.Parent.Humanoid:MoveTo(rest.Position)
end
end
end)
end
Hey, first ever time using this website to help others so correct me on any mistakes in this reply
After taking a look at your code, I suggest you to remove the debounce waits, and make a function to check if theres any grown plots, and if it returns as false, go to the resting spot.
Like this (also use your humanoid variable)
-- Variables
local humanoid = script.Parent.Humanoid
local soil = game.Workspace.Soils:GetChildren()
local rest = game.Workspace.RestingPosition
local function checkGrownPlots()
for _, G in ipairs(soil) do
if G.GrownValue.Value == true then
print("Moving to a grown plot:", G.Name) --also use prints to help debugging
humanoid:MoveTo(G.Position)
return true
end
end
return false
end
-- Script Logic
for _, G in ipairs(soil) do
G.GrownValue:GetPropertyChangedSignal("Value"):Connect(function()
if not checkGrownPlots() then --uses the returned value
print("Moving to resting position")
humanoid:MoveTo(rest.Position)
end
end)
end```
incase that doesnt work, feel free to reply and send out a video of the updated script (although i rarely use this website, so it might take some time for a response)