Unsure if I understood you correctly (if I didn’t, then my apologies), but if you look at when I did gameplay tests and stuff, it does get through that if statement, and in the more recent version of the code, which I’ll put down, I also tried to get rid of the function entirely, as it is quite unnecessary, and it can be easily avoided
local a = Instance.new("Folder", script)
a.Name = "NPCs"
for i,x in pairs(workspace.Map.NPCs:GetChildren()) do
coroutine.wrap(function()
print("loading "..x.Name)
local anim = script.Animate:Clone()
anim.Parent = x
anim.Enabled = true
local Finishedyet = false
local SmthToDo = false
local funcfin = Instance.new("BoolValue", a)
funcfin.Name = x.Name.."funcfin"
local jobval = Instance.new("StringValue", a)
jobval.Name = x.Name.."jobval"
local p = sp.new(x)
local Wander = Instance.new("BoolValue", a)
Wander.Name = x.Name.."wander"
for i = 1,12 do
local a = x.GInformation.Skills:GetChildren()[math.random(1,#x.GInformation.Skills:GetChildren())]
a.Value +=1
end
x.GInformation.Status.Age.Value = math.random(19,24)
local a = x.GInformation.Traits:GetChildren()[math.random(1,#x.GInformation.Traits:GetChildren())]
a.Value = true
--Main
while true do
wait(.2)
local stgs = workspace.Map.SandboxSettings
x.GInformation.Status.Fun.Value -=.05*stgs.FunRate.Value
x.GInformation.Status.Hunger.Value -=.0025*stgs.HungerRate.Value
x.GInformation.Status.Thirst.Value -=.005*stgs.ThirstRate.Value
if x.GInformation.Traits.Insomniac.Value == false then
if game.Lighting:GetMinutesAfterMidnight() > 18*60 then
x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
end
else
if game.Lighting:GetMinutesAfterMidnight() <6*60 then
x.GInformation.Status.Energy.Value -=.2*stgs.EnergyRate.Value
end
end
if SmthToDo == false and Wander.Value == false and x.GInformation.Task.Value == false then
print(jobval.Value)
if jobval.Value == "Woodworker" then
print("Working")
local Con_A, Con_B
if not workspace.Map.Zones.Woodwork.CanCollide then
Con_A = workspace.Map.Zones.Woodwork.Touched:Connect(function () end)
end
--(repeat for PartB, using variable Con_B)
local TouchingParts = workspace.Map.Zones.Woodwork:GetTouchingParts()
local Touching = false
for Index, Other in pairs(TouchingParts) do
if Other == workspace.Map.Zones.Woodwork then
Touching = true
break
end
end
if Con_A then Con_A:Disconnect() end
if Con_B then Con_B:Disconnect() end
for i, z in pairs(TouchingParts) do
print(z)
if z:FindFirstChild("Chop") and SmthToDo == false then
SmthToDo = true
x.GInformation.Task.Value = true
local obj = z:FindFirstAncestorOfClass("Model")
if x.GInformation.Inv:FindFirstChild("Axe") then
obj.PrimaryPart.Chop.Used.Value = true
end
p:Run(obj.PrimaryPart.Pos.WorldPosition)
--Pathfind(NPC, place.WorldPosition)
p.Reached:Connect(function()
if x.GInformation.Inv:FindFirstChild("Axe") then
local axe = x.GInformation.Inv.Axe.Value:Clone()
axe.Handle.PickUp:Destroy()
axe.Handle.Fall.PlayOnRemove = true
axe.Parent = x
local M6 = Instance.new("Motor6D", x.HumanoidRootPart)
M6.Part0 = x.HumanoidRootPart
M6.Part1 = axe.PrimaryPart
coroutine.wrap(function()
tws:Create(x.HumanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {CFrame = CFrame.lookAt(x.HumanoidRootPart.Position, Vector3.new(obj.PrimaryPart.Position.X, x.HumanoidRootPart.Position.Y , obj.PrimaryPart.Position.Z))}):Play()
end)
local num = ((math.random(6380,7490)*obj.PrimaryPart.Chop.RankHigherThan.Value)*10/(x.GInformation.Status.Energy.Value*(x.GInformation.Status.Energy.Value*.1)))/2.7
local a = x.Humanoid:LoadAnimation(axe.Use)
a:Play()
axe.Handle.Chop:Play()
wait(num)
axe.Handle.Chop:Stop()
a:Stop()
for i, x in pairs(obj.PrimaryPart.Chop.Output:GetChildren()) do
local num = math.random(x.Min.Value, x.Max.Value)
for i = 1, num do
local model = x.Value:Clone()
model.Parent = workspace.Map.Interactables
model.PrimaryPart.Position = obj.PrimaryPart.Position
end
end
axe:Destroy()
M6:Destroy()
obj:Destroy()
x.GInformation.Task.Value = false
SmthToDo = false
else
local popup = script.InfPopup:Clone()
popup.Parent = x
dsv:AddItem(popup, 2)
popup.Frame.InfMain.Text = x.Name.." doesn't have an axe"
tws:Create(popup, TweenInfo.new(2), {ExtentsOffsetWorldSpace = Vector3.new(0,2,0)}):Play()
for i, x in pairs(popup:GetDescendants()) do
if x:IsA("TextLabel") then
tws:Create(x, TweenInfo.new(2), {TextTransparency = 1, TextStrokeTransparency = 1}):Play()
end
end
popup.Frame.InfBack.Text = popup.Frame.InfMain.Text
x.GInformation.Task.Value = false
SmthToDo = false
end
end)
end
end
end
--[[
Wander.Value = true
p:Run(x.HumanoidRootPart.Position+Vector3.new(math.random(-10,10),0, math.random(-10,10)), true)
p.Reached:Connect(function()
wait(math.random(3,5))
Wander.Value = false
end)--]]
end
if x.GInformation.Task.Value == false then
if x.GInformation.Status.Energy.Value <=50 then
local food = updateTarget(x, "Sleep")
if food ~= nil and food.Sleep.Value == false then
food.Sleep.Used.Value = true
SmthToDo = true
p:Run(food.Position)
p.Reached:Connect(function()
Finishedyet = true
x.GInformation.Task.Value = true
print("sleep")
repeat wait(.1)
x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
until x.GInformation.Status.Energy.Value >=80
x.GInformation.Task.Value = false
food.Sleep.Used.Value = false
SmthToDo = false
end)
end
end
if x.GInformation.Status.Energy.Value <=10 then
local food = updateTarget(x, "Sleep")
if food == nil then
SmthToDo = true
Finishedyet = true
x.GInformation.Task.Value = true
print("Pass out")
repeat wait(.1)
x.GInformation.Status.Energy.Value +=.2*stgs.EnergyRate.Value*3
until x.GInformation.Status.Energy.Value >=80
x.GInformation.Task.Value = false
SmthToDo = false
end
end
if x.GInformation.Status.Hunger.Value <=70 then
local GotFood = false
for i, z in pairs(x.GInformation.Inv:GetChildren()) do
if z:IsA("ObjectValue") then
if z.Value.PrimaryPart:FindFirstChild("Eat") then
GotFood = true
wait(3)
x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
z:Destroy()
end
end
end
if GotFood == false then
local food = updateTarget(x, "Eat")
if food ~= nil then
SmthToDo = true
p:Run(food.Position)
p.Reached:Connect(function()
food.Drink.BeingUsed.Value = false
Finishedyet = true
local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Eat.Model.Value):Clone()
Model.Parent = x.HumanoidRootPart
Model.CFrame = x.Humanoid.RootPart.CFrame
dsv:AddItem(Model, 3)
local Amount = food.Eat.Nutrition.Value
food:FindFirstAncestorOfClass("Model"):Destroy()
wait(3)
x.GInformation.Status.Hunger.Value += Amount
x.GInformation.Task.Value = false
food.Eat.BeingUsed.Value = false
SmthToDo = false
end)
end
end
--SearchForFood
end
--x.GInformation.Job.Changed:Connect(function(val)
-- warn(x.Name.."is now a "..val)
-- jobval.Value = val
--end)
if x.GInformation.Status.Thirst.Value <=70 then
local GotFood = false
for i, z in pairs(x.GInformation.Inv:GetChildren()) do
if z:IsA("ObjectValue") then
if z.Value.PrimaryPart:FindFirstChild("Drink") then
GotFood = true
wait(3)
x.GInformation.Status.Hunger.Value += z.Value.PrimaryPart.Eat.Nutrition.Value
z:Destroy()
end
end
end
if GotFood == false then
local food = updateTarget(x, "Drink")
if food ~= nil then
SmthToDo = true
p:Run(food.Position)
p.Reached:Connect(function()
food.Drink.BeingUsed.Value = true
Finishedyet = true
local Model = game.ReplicatedStorage.Objects:FindFirstChild(food.Drink.Model.Value):Clone()
Model.Parent = x.HumanoidRootPart
Model.CFrame = x.Humanoid.RootPart.CFrame
dsv:AddItem(Model, 3)
local Amount = food.Drink.Nutrition.Value
food:FindFirstAncestorOfClass("Model"):Destroy()
wait(3)
x.GInformation.Status.Thirst.Value += Amount
x.GInformation.Task.Value = false
food.Drink.BeingUsed.Value = false
SmthToDo = false
end)
end
end
--SearchForFood
end
if x.GInformation.Status.Fun.Value <=70 then
print("Bored")
local NPC = updateTargetNPC(x, "NPC", "Player", "Friendly")
if NPC ~= nil then
SmthToDo = true
p:Run(NPC.InteractionPos.WorldCFrame.Position)
p.Reached:Connect(function()
end)
--SearchForDrinks
end
end
end
end
end)()
end
game.ReplicatedStorage.Events.Assigment.OnServerEvent:Connect(function(plr, job, NPC)
NPC.GInformation.Job.Value = job
script.NPCs[NPC.Name.."jobval"].Value = job
print("changed to "..job)
end)