| |
|
| |
|
| | local CollectionService = game:GetService("CollectionService")
|
| |
|
| |
|
| | local function processLog(logPart, machineType)
|
| | local state = logPart:GetAttribute("ProcessState") or "Raw"
|
| | local treeType = logPart:GetAttribute("TreeType")
|
| |
|
| | if machineType == "Stripper" and state == "Raw" then
|
| |
|
| | logPart:SetAttribute("ProcessState", "Stripped")
|
| |
|
| |
|
| | local newSize = logPart.Size * 0.9
|
| | logPart.Size = newSize
|
| | logPart.Material = Enum.Material.Wood
|
| |
|
| | elseif machineType == "Sawmill" and (state == "Raw" or state == "Stripped") then
|
| |
|
| | logPart:SetAttribute("ProcessState", "Plank")
|
| |
|
| |
|
| | local volume = logPart.Size.X * logPart.Size.Y * logPart.Size.Z
|
| |
|
| | local plankThickness = 0.5
|
| | local length = logPart.Size.Y
|
| | local width = (volume / length) / plankThickness
|
| |
|
| |
|
| | width = math.clamp(width, 1, 4)
|
| |
|
| | logPart.Size = Vector3.new(width, length, plankThickness)
|
| | logPart.Material = Enum.Material.WoodPlanks
|
| | logPart.BrickColor = BrickColor.new("Burlap")
|
| |
|
| |
|
| | logPart.Anchored = false
|
| | end
|
| | end
|
| |
|
| |
|
| | local function bindMachine(machineModel)
|
| | local triggerPart = machineModel:FindFirstChild("ProcessTrigger")
|
| | if not triggerPart then return end
|
| |
|
| | local machineType = machineModel:GetAttribute("MachineType") or "Sawmill"
|
| |
|
| | local debounce = {}
|
| |
|
| | triggerPart.Touched:Connect(function(hit)
|
| |
|
| | if CollectionService:HasTag(hit, "TreeSegment") then
|
| |
|
| | if not debounce[hit] then
|
| | debounce[hit] = true
|
| |
|
| |
|
| | processLog(hit, machineType)
|
| |
|
| |
|
| | task.delay(1, function()
|
| | debounce[hit] = nil
|
| | end)
|
| | end
|
| | end
|
| | end)
|
| | end
|
| |
|
| |
|
| | CollectionService:GetInstanceAddedSignal("ProcessingMachine"):Connect(bindMachine)
|
| |
|
| | for _, machine in pairs(CollectionService:GetTagged("ProcessingMachine")) do
|
| | bindMachine(machine)
|
| | end
|
| |
|