I am working on a work order system, I am having issues where the script isn’t recognizing an object its supposed to detect. I don’t understand why, there shouldn’t be any spawning before it can detect things because the script is what prompts the server to spawn the item. And the item is being spawned in normally.
Code:
---- NGH Work Order Script (Client)
---- Task: Lumber Mill Switching
--- created: 2/13/2024
-- Original Programer: Sterling_ODeaghaidh(10283957)
-------------------------Variables-------------------------
local PLR = game.Players.LocalPlayer
local OrderFolder = script.Folder.Value
local Gamespace = game.Workspace
local ClaimValue = OrderFolder.Claimed
local Event = game.ReplicatedStorage.OrderEvent
local Event1 = game.ReplicatedStorage.HubEvent
local Spot = Vector3.new(-4143.966, 88.461, 338.739)
---------------------- ----------------------
progress = 0
DB = false
Started = false
MS = false
Objects = {}
CurrentLoco = nil
CurrentPoint = nil
T1 = 0
T2 = 0
T3 = 0
-----------------------------------------------------------
--Setup
-- Detecting spawned objects
Gamespace.ChildAdded:Connect(function(Item)
if Item.Name == "Startpoint" then
local Folder = Item:WaitForChild("Folder")
local Sensor = Item:WaitForChild("SenseObject")
if Folder.Value == OrderFolder then
table.insert(Objects,Item)
CurrentPoint = Item
Item.Transparency = 0
Sensor.Value = CurrentLoco.Part
end
end
----
if Item.Name == "Stop1" then
local Folder = Item:WaitForChild("Folder")
table.insert(Objects,Item)
CurrentPoint = Item
if Folder.Value == OrderFolder then
Item.Transparency = 0
end
end
----
if Item.Name == "WOSNR2" then
local Folder = Item:WaitForChild("Folder")
table.insert(Objects,Item)
if Folder.Value == OrderFolder then
CurrentLoco = Item
end
end
end)
----
Event:FireServer("Altspawn","WOSNR2",OrderFolder.Name)
wait(.5)
Event:FireServer("Notify","Enter the locomotive to begin.")
PLR:RequestStreamAroundAsync(Spot)
PLR.Character.Humanoid.Sit = false
PLR.Character.HumanoidRootPart.Anchored = true
PLR.Character:moveTo(Spot)
wait(5)
PLR.Character.HumanoidRootPart.Anchored = false
-- Event
Event.OnClientEvent:Connect(function(M,V1,V2,V3,V4)
if M == "Start" then
if Started == false then
Started = true
Event:FireServer("Altspawn","Startpoint",OrderFolder.Name)
Event:FireServer("Notify","Proceed to first waypoint.")
end
end
---
if M == "LogCars" then
Event:FireServer("Altspawn","LogCars",OrderFolder.Name)
Event:FireServer("Despawn",CurrentPoint)
Event:FireServer("Altspawn","Stop1",OrderFolder.Name)
Event:FireServer("Notify","Shunt the log cars into the unlading track at the lumber mill.")
end
----
if M =="CancelJob" then
PLR.Character.Humanoid.Sit = false
Event:FireServer("ClearAll",OrderFolder)
for index, item in ipairs(Objects) do
if item ~= nil then
Event:FireServer("Despawn",item)
end
end
CurrentPoint.Parent = OrderFolder
OrderFolder:Destroy()
end
----
if M == "Restart" then
PLR.Character.Humanoid.Sit = false
Event:FireServer("ClearAll",OrderFolder)
for index, item in ipairs(Objects) do
if item ~= nil then
Event:FireServer("Despawn",item)
end
end
CurrentPoint.Parent = OrderFolder
script.Enabled = false
wait(1)
script.Enabled = true
end
----
if M == "Im Here" then
print("Heard")
local Folder = V1:WaitForChild("Folder")
if Folder and Folder.Value == OrderFolder then
print("Match Found")
CurrentLoco = V1
end
end
end)