local Workspace = game:GetService("Workspace") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local ServerScriptService = game:GetService("ServerScriptService") local RunService = game:GetService("RunService") local ServerStorage = game:GetService("ServerStorage") local Manager = require(ServerScriptService.PlayerData.Manager) local Terrain = Workspace:WaitForChild("Terrain") local Clouds = Terrain:WaitForChild("Clouds") local PlantWheatEvent = ReplicatedStorage.Remotes:WaitForChild("PlantWheatEvent") local UpdateCountdownEvent = ReplicatedStorage.Remotes:WaitForChild("UpdateCountdownEvent") local PlantPotatoEvent = ReplicatedStorage.Remotes:WaitForChild("PlantPotatoEvent") local UpdatePotatoEvent = ReplicatedStorage.Remotes:WaitForChild("UpdatePotatoEvent") local PlantCarrotEvent = ReplicatedStorage.Remotes:WaitForChild("PlantCarrotEvent") local UpdateCarrotEvent = ReplicatedStorage.Remotes:WaitForChild("UpdateCarrotEvent") local PlantCornEvent = ReplicatedStorage.Remotes:WaitForChild("PlantCornEvent") local UpdateCornEvent = ReplicatedStorage.Remotes:WaitForChild("UpdateCornEvent") local PlantTomatoEvent = ReplicatedStorage.Remotes:WaitForChild("PlantTomatoEvent") local UpdateTomatoEvent = ReplicatedStorage.Remotes:WaitForChild("UpdateTomatoEvent") local WaterCanEvent = ReplicatedStorage.Remotes:WaitForChild("WaterCanEvent") local UpdateWaterEvent = ReplicatedStorage.Remotes:WaitForChild("UpdateWaterEvent") local Growth = ServerStorage.Growth local Remotes = ReplicatedStorage.Remotes local function getPlayerFields(player) local playerId = player.UserId local fieldsFolderName = playerId .. "'s Fields" local fieldsFolder = Workspace:FindFirstChild("Fields") if fieldsFolder then return fieldsFolder:WaitForChild(fieldsFolderName) end return nil end local function getCropField(player) local playerFields = getPlayerFields(player) return playerFields end local function getPlayerPersonalCropField(player) local playerId = player.UserId local fieldsFolderName = playerId .. "'s Fields" local fieldsFolder = Workspace:FindFirstChild("Fields") if fieldsFolder then local playerPersonalCropField = fieldsFolder:FindFirstChild(fieldsFolderName) if playerPersonalCropField then return playerPersonalCropField end end return nil end local function createWateringIcon(field) local wateringIcon = Instance.new("BillboardGui") wateringIcon.Name = "WateringIcon" wateringIcon.Size = UDim2.new(0, 50, 0, 50) wateringIcon.StudsOffset = Vector3.new(0, 7, 0) wateringIcon.MaxDistance = 70 wateringIcon.Parent = field wateringIcon.Enabled = false -- Set this to false by default local iconImage = Instance.new("ImageLabel") iconImage.Size = UDim2.new(1, 0, 1, 0) iconImage.BackgroundTransparency = 1 iconImage.Image = "rbxassetid://13334216543" iconImage.Parent = wateringIcon return wateringIcon end local function updateWateringIcons(player) local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local isWatered = field.PrimaryPart:GetAttribute("IsWatered") local wateringIcon = field:FindFirstChild("WateringIcon") if not isWatered then if not wateringIcon then wateringIcon = createWateringIcon(field) end wateringIcon.Enabled = true else if wateringIcon then wateringIcon.Enabled = false end end end end local function waterField(player, field, autoWatered) if field and field.Parent then local FieldOwner = field.Parent.Name:match("^(%d+)'s Fields$") if FieldOwner and tonumber(FieldOwner) == player.UserId then -- Only water the field if it's not watered already if not field.PrimaryPart:GetAttribute("IsWatered") then -- Get the player profile local profile = Manager.Profiles[player] if profile then -- Check if the player has enough water or if this is automatic watering if profile.Data.Water > 0 or autoWatered then -- Water the field and decrease the water amount from the player's water storage field.PrimaryPart:SetAttribute("IsWatered", true) field.PrimaryPart.Color = Color3.fromRGB(44, 31, 15) -- Only decrease the water amount if this is not automatic watering if not autoWatered then Manager.AdjustWater(player, -1) -- Assume that watering a field consumes 1 unit of water end end end end end end end local isRaining = false local function autoWaterFields() while true do wait(1) local cloudDensity = Clouds.Cover if cloudDensity >= 1 then isRaining = true else isRaining = false end while isRaining do for _, player in ipairs(Players:GetPlayers()) do local playerFields = getPlayerFields(player) if playerFields then for _, field in ipairs(playerFields:GetChildren()) do waterField(player, field, true) -- passing true for autoWatered end end end wait(1) cloudDensity = Clouds.Cover if cloudDensity < 1 then isRaining = false end end end end local function startWateringIconsUpdater(player) while true do wait(0.1) updateWateringIcons(player) end end local function onWaterAmountChanged(player) startWateringIconsUpdater(player) end Remotes.UpdateMasteryEvent.OnServerEvent:Connect(function(player, amount) Manager.AdjustMastery(player, amount) end) local sickleMultipliers = { StoneSickle = 1, CopperSickle = 1.2, RustySickle = 1.4, IronSickle = 1.6, SilverSickle = 1.8, GoldSickle = 2, DiamondSickle = 2.2, PlatinumSickle = 2.5, DivineSickle = 3 } local function onPromptTriggered(prompt, player) local field = prompt.Parent local wheatStage3 = field:FindFirstChild("WheatStage3") local character = player.Character if not character then return end local function hasSickle() local sickle for _, item in ipairs(character:GetChildren()) do if Manager.SickleCosts[item.Name] ~= nil then sickle = item break end end return sickle end local sickle = hasSickle() if not sickle then return end if wheatStage3 then if prompt.Enabled == false then return end prompt.Enabled = false character.Humanoid.WalkSpeed = 0 -- Play the harvesting animation local PlayAnimationEvent = sickle:FindFirstChild("PlayAnimationEvent") if PlayAnimationEvent then PlayAnimationEvent:FireClient(player) end -- Wait for the animation to finish wait(0.6) -- Adjust this value to match the animation duration -- Destroy the plant wheatStage3:Destroy() field.PrimaryPart.Color = Color3.fromRGB(72, 48, 24) field.PrimaryPart:SetAttribute("IsWatered", false) -- Call updateWateringIcons here updateWateringIcons(player) -- Destroy the ProximityPrompt prompt:Destroy() -- Give the player 10 Credits local manager = require(ServerScriptService.PlayerData.Manager) -- Add harvested Wheat to the player's inventory manager.AdjustWheat(player, 10) Manager.AdjustExp(player, 10 * sickleMultipliers[sickle.Name]) -- Enable player's movement character.Humanoid.WalkSpeed = 16 -- Reset the walk speed to the default value end end local function onPotatoPromptTriggered(prompt, player) local field = prompt.Parent local potatoStage3 = field:FindFirstChild("PotatoStage3") local character = player.Character if not character then return end local function hasSickle() local sickle for _, item in ipairs(character:GetChildren()) do if Manager.SickleCosts[item.Name] ~= nil then sickle = item break end end return sickle end local sickle = hasSickle() if not sickle then return end if potatoStage3 then if prompt.Enabled == false then return end prompt.Enabled = false -- Disable player's movement character.Humanoid.WalkSpeed = 0 -- Play the harvesting animation local PlayAnimationEvent = sickle:FindFirstChild("PlayAnimationEvent") if PlayAnimationEvent then PlayAnimationEvent:FireClient(player) end -- Wait for the animation to finish wait(0.6) -- Adjust this value to match the animation duration -- Destroy the plant potatoStage3:Destroy() field.PrimaryPart.Color = Color3.fromRGB(72, 48, 24) field.PrimaryPart:SetAttribute("IsWatered", false) -- Destroy the ProximityPrompt prompt:Destroy() -- Give the player 10 Credits local manager = require(ServerScriptService.PlayerData.Manager) -- Add harvested Potatoes to the player's inventory manager.AdjustPotatoes(player, 1) Manager.AdjustExp(player, 20 * sickleMultipliers[sickle.Name]) -- Enable player's movement character.Humanoid.WalkSpeed = 16 -- Reset the walk speed to the default value end end local function onCarrotPromptTriggered(prompt, player) local field = prompt.Parent local carrotStage3 = field:FindFirstChild("CarrotStage3") local character = player.Character if not character then return end local function hasSickle() local sickle for _, item in ipairs(character:GetChildren()) do if Manager.SickleCosts[item.Name] ~= nil then sickle = item break end end return sickle end local sickle = hasSickle() if not sickle then return end if carrotStage3 then if prompt.Enabled == false then return end prompt.Enabled = false -- Disable player's movement character.Humanoid.WalkSpeed = 0 -- Play the harvesting animation local PlayAnimationEvent = sickle:FindFirstChild("PlayAnimationEvent") if PlayAnimationEvent then PlayAnimationEvent:FireClient(player) end -- Wait for the animation to finish wait(0.6) -- Adjust this value to match the animation duration -- Destroy the plant carrotStage3:Destroy() field.PrimaryPart.Color = Color3.fromRGB(72, 48, 24) field.PrimaryPart:SetAttribute("IsWatered", false) -- Destroy the ProximityPrompt prompt:Destroy() -- Give the player 10 Credits local manager = require(ServerScriptService.PlayerData.Manager) -- Add harvested Carrots to the player's inventory manager.AdjustCarrots(player, 10) Manager.AdjustExp(player, 30 * sickleMultipliers[sickle.Name]) -- Enable player's movement character.Humanoid.WalkSpeed = 16 -- Reset the walk speed to the default value end end local function onCornPromptTriggered(prompt, player) local field = prompt.Parent local cornStage3 = field:FindFirstChild("CornStage3") local character = player.Character if not character then return end local function hasSickle() local sickle for _, item in ipairs(character:GetChildren()) do if Manager.SickleCosts[item.Name] ~= nil then sickle = item break end end return sickle end local sickle = hasSickle() if not sickle then return end if cornStage3 then if prompt.Enabled == false then return end prompt.Enabled = false -- Disable player's movement character.Humanoid.WalkSpeed = 0 -- Play the harvesting animation local PlayAnimationEvent = sickle:FindFirstChild("PlayAnimationEvent") if PlayAnimationEvent then PlayAnimationEvent:FireClient(player) end -- Wait for the animation to finish wait(0.6) -- Adjust this value to match the animation duration -- Destroy the plant cornStage3:Destroy() field.PrimaryPart.Color = Color3.fromRGB(72, 48, 24) field.PrimaryPart:SetAttribute("IsWatered", false) -- Destroy the ProximityPrompt prompt:Destroy() -- Give the player 10 Credits local manager = require(ServerScriptService.PlayerData.Manager) -- Add harvested Corns to the player's inventory manager.AdjustCorns(player, 10 ) Manager.AdjustExp(player, 40 * sickleMultipliers[sickle.Name]) -- Enable player's movement character.Humanoid.WalkSpeed = 16 -- Reset the walk speed to the default value end end local function onTomatoPromptTriggered(prompt, player) local field = prompt.Parent local tomatoStage3 = field:FindFirstChild("TomatoStage3") local character = player.Character if not character then return end local function hasSickle() local sickle for _, item in ipairs(character:GetChildren()) do if Manager.SickleCosts[item.Name] ~= nil then sickle = item break end end return sickle end local sickle = hasSickle() if not sickle then return end if tomatoStage3 then if prompt.Enabled == false then return end prompt.Enabled = false -- Disable player's movement character.Humanoid.WalkSpeed = 0 -- Play the harvesting animation local PlayAnimationEvent = sickle:FindFirstChild("PlayAnimationEvent") if PlayAnimationEvent then PlayAnimationEvent:FireClient(player) end -- Wait for the animation to finish wait(0.6) -- Adjust this value to match the animation duration -- Destroy the plant tomatoStage3:Destroy() field.PrimaryPart.Color = Color3.fromRGB(72, 48, 24) field.PrimaryPart:SetAttribute("IsWatered", false) -- Destroy the ProximityPrompt prompt:Destroy() -- Give the player 10 Credits local manager = require(ServerScriptService.PlayerData.Manager) -- Add harvested Tomatoes to the player's inventory manager.AdjustTomato(player, 10) Manager.AdjustExp(player, 50 * sickleMultipliers[sickle.Name]) -- Enable player's movement character.Humanoid.WalkSpeed = 16 -- Reset the walk speed to the default value end end local function createProximityPrompt(field, player) local proximityPrompt = Instance.new("ProximityPrompt", field) proximityPrompt.ActionText = "Wheat" proximityPrompt.ObjectText = "Use Sicle To Harvest" proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E proximityPrompt.GamepadKeyCode = Enum.KeyCode.ButtonA -- Add this line for gamepad support proximityPrompt.RequiresLineOfSight = false proximityPrompt.MaxActivationDistance = 10 proximityPrompt.Triggered:Connect(function(triggeringPlayer) if triggeringPlayer.UserId == player.UserId then onPromptTriggered(proximityPrompt, player) end end) end local function createPotatoProximityPrompt(field, player) local proximityPrompt = Instance.new("ProximityPrompt", field) proximityPrompt.ActionText = "Potato" proximityPrompt.ObjectText = "Use Sicle To Harvest" proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E proximityPrompt.GamepadKeyCode = Enum.KeyCode.ButtonA -- Add this line for gamepad support proximityPrompt.RequiresLineOfSight = false proximityPrompt.MaxActivationDistance = 10 proximityPrompt.Triggered:Connect(function(triggeringPlayer) if triggeringPlayer.UserId == player.UserId then onPotatoPromptTriggered(proximityPrompt, player) end end) end local function createCarrotProximityPrompt(field, player) local proximityPrompt = Instance.new("ProximityPrompt", field) proximityPrompt.ActionText = "Carrot" proximityPrompt.ObjectText = "Use Sicle To Harvest" proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E proximityPrompt.GamepadKeyCode = Enum.KeyCode.ButtonA proximityPrompt.RequiresLineOfSight = false proximityPrompt.MaxActivationDistance = 10 proximityPrompt.Triggered:Connect(function(triggeringPlayer) if triggeringPlayer.UserId == player.UserId then onCarrotPromptTriggered(proximityPrompt, player) end end) end local function createCornProximityPrompt(field, player) local proximityPrompt = Instance.new("ProximityPrompt", field) proximityPrompt.ActionText = "Corn" proximityPrompt.ObjectText = "Use Sicle To Harvest" proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E proximityPrompt.GamepadKeyCode = Enum.KeyCode.ButtonA proximityPrompt.RequiresLineOfSight = false proximityPrompt.MaxActivationDistance = 10 proximityPrompt.Triggered:Connect(function(triggeringPlayer) if triggeringPlayer.UserId == player.UserId then onCornPromptTriggered(proximityPrompt, player) end end) end local function createTomatoProximityPrompt(field, player) local proximityPrompt = Instance.new("ProximityPrompt", field) proximityPrompt.ActionText = "Tomato" proximityPrompt.ObjectText = "Use Sicle To Harvest" proximityPrompt.KeyboardKeyCode = Enum.KeyCode.E proximityPrompt.GamepadKeyCode = Enum.KeyCode.ButtonA proximityPrompt.RequiresLineOfSight = false proximityPrompt.MaxActivationDistance = 10 proximityPrompt.Triggered:Connect(function(triggeringPlayer) if triggeringPlayer.UserId == player.UserId then onTomatoPromptTriggered(proximityPrompt, player) end end) end local function setPartProperties(model) for _, part in ipairs(model:GetDescendants()) do if part:IsA("BasePart") then part.CanCollide = false part.CanQuery = false part.CanTouch = false end end end local function getCropStages(field) local stages = {} for _, child in ipairs(field:GetChildren()) do local stageName = child.Name if stageName:match("Stage") then -- if the child is a stage stages[stageName] = child end end return stages end local function plantWheat(player) local profile = Manager.Profiles[player] if not profile then return end if profile.Data.WheatSeeds < 1 then return end local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local nearestField, minDistance = nil, math.huge local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local distance = (humanoidRootPart.Position - field.PrimaryPart.Position).Magnitude if distance < minDistance then nearestField = field minDistance = distance end end if minDistance <= 10 then if nearestField.PrimaryPart:GetAttribute("IsWatered") ~= true then -- Check if the field is watered return end local cropStages = getCropStages(nearestField) -- use the helper function -- check if any crop stage exists in the field for _, stage in pairs(cropStages) do if stage then return end end Manager.AdjustWheatSeeds(player, -1) local wheatStage1 = Growth.WheatStage1:Clone() setPartProperties(wheatStage1) wheatStage1.Parent = nearestField wheatStage1:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) updateWateringIcons(player) local countdownGui = Instance.new("BillboardGui") countdownGui.Name = "CountdownGui" countdownGui.Size = UDim2.new(0, 50, 0, 50) countdownGui.StudsOffset = Vector3.new(0, 7, 0) countdownGui.Parent = nearestField local maxVisibleDistance = 20 local function updateCountdownVisibility() if not player.Character then return end local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local distance = (humanoidRootPart.Position - nearestField.PrimaryPart.Position).Magnitude countdownGui.Enabled = distance <= maxVisibleDistance end local connection connection = RunService.Heartbeat:Connect(function() updateCountdownVisibility() end) nearestField.AncestryChanged:Connect(function() if nearestField.Parent == nil then connection:Disconnect() end end) local countdownLabel = Instance.new("TextLabel") countdownLabel.Name = "CountdownLabel" countdownLabel.Size = UDim2.new(1, 0, 1, 0) countdownLabel.BackgroundTransparency = 1 countdownLabel.Font = Enum.Font.SourceSansBold countdownLabel.TextColor3 = Color3.new(1, 1, 1) countdownLabel.TextScaled = true countdownLabel.Parent = countdownGui local stage1GrowthTime = 5 local stage2GrowthTime = 5 local totalGrowthTime = stage1GrowthTime + stage2GrowthTime local wheatStage2 for i = totalGrowthTime, 1, -1 do -- Replace the line that fires UpdateCountdownEvent with the following line UpdateCountdownEvent:FireAllClients(nearestField, i) wait(1) if i == stage1GrowthTime + 1 then wheatStage1:Destroy() wheatStage2 = Growth.WheatStage2:Clone() setPartProperties(wheatStage2) wheatStage2.Parent = nearestField wheatStage2:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) end end wheatStage2:Destroy() local wheatStage3 = Growth.WheatStage3:Clone() setPartProperties(wheatStage3) wheatStage3.Parent = nearestField wheatStage3:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) createProximityPrompt(nearestField, player) updateWateringIcons(player) countdownGui:Destroy() end end local function plantPotato(player) local profile = Manager.Profiles[player] if not profile then return end if profile.Data.PotatoSeeds < 1 then return end local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local nearestField, minDistance = nil, math.huge local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local distance = (humanoidRootPart.Position - field.PrimaryPart.Position).Magnitude if distance < minDistance then nearestField = field minDistance = distance end end if minDistance <= 10 then if nearestField.PrimaryPart:GetAttribute("IsWatered") ~= true then -- Check if the field is watered return end local cropStages = getCropStages(nearestField) -- use the helper function -- check if any crop stage exists in the field for _, stage in pairs(cropStages) do if stage then return end end Manager.AdjustPotatoSeeds(player, -1) local potatoStage1 = Growth.PotatoStage1:Clone() setPartProperties(potatoStage1) potatoStage1.Parent = nearestField potatoStage1:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) updateWateringIcons(player) -- Rest of the code local countdownGui = Instance.new("BillboardGui") countdownGui.Name = "CountdownGui" countdownGui.Size = UDim2.new(0, 50, 0, 50) countdownGui.StudsOffset = Vector3.new(0, 7, 0) countdownGui.Parent = nearestField local maxVisibleDistance = 20 local function updateCountdownVisibility() if not player.Character then return end local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local distance = (humanoidRootPart.Position - nearestField.PrimaryPart.Position).Magnitude countdownGui.Enabled = distance <= maxVisibleDistance end local connection connection = RunService.Heartbeat:Connect(function() updateCountdownVisibility() end) nearestField.AncestryChanged:Connect(function() if nearestField.Parent == nil then connection:Disconnect() end end) local countdownLabel = Instance.new("TextLabel") countdownLabel.Name = "CountdownLabel" countdownLabel.Size = UDim2.new(1, 0, 1, 0) countdownLabel.BackgroundTransparency = 1 countdownLabel.Font = Enum.Font.SourceSansBold countdownLabel.TextColor3 = Color3.new(1, 1, 1) countdownLabel.TextScaled = true countdownLabel.Parent = countdownGui local stage1GrowthTime = 5 local stage2GrowthTime = 5 local totalGrowthTime = stage1GrowthTime + stage2GrowthTime local potatoStage2 for i = totalGrowthTime, 1, -1 do UpdateCountdownEvent:FireAllClients(nearestField, i) wait(1) if i == stage1GrowthTime + 1 then potatoStage1:Destroy() potatoStage2 = Growth.PotatoStage2:Clone() setPartProperties(potatoStage2) potatoStage2.Parent = nearestField potatoStage2:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) end end potatoStage2:Destroy() local potatoStage3 = Growth.PotatoStage3:Clone() setPartProperties(potatoStage3) potatoStage3.Parent = nearestField potatoStage3:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) createPotatoProximityPrompt(nearestField, player) updateWateringIcons(player) countdownGui:Destroy() end end local function plantCarrot(player) local profile = Manager.Profiles[player] if not profile then return end if profile.Data.CarrotSeeds < 1 then return end local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local nearestField, minDistance = nil, math.huge local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local distance = (humanoidRootPart.Position - field.PrimaryPart.Position).Magnitude if distance < minDistance then nearestField = field minDistance = distance end end if minDistance <= 10 then if nearestField.PrimaryPart:GetAttribute("IsWatered") ~= true then -- Check if the field is watered return end local cropStages = getCropStages(nearestField) -- use the helper function -- check if any crop stage exists in the field for _, stage in pairs(cropStages) do if stage then return end end Manager.AdjustCarrotSeeds(player, -1) local carrotStage1 = Growth.CarrotStage1:Clone() setPartProperties(carrotStage1) carrotStage1.Parent = nearestField carrotStage1:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) updateWateringIcons(player) local countdownGui = Instance.new("BillboardGui") countdownGui.Name = "CountdownGui" countdownGui.Size = UDim2.new(0, 50, 0, 50) countdownGui.StudsOffset = Vector3.new(0, 7, 0) countdownGui.Parent = nearestField local maxVisibleDistance = 20 local function updateCountdownVisibility() if not player.Character then return end local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local distance = (humanoidRootPart.Position - nearestField.PrimaryPart.Position).Magnitude countdownGui.Enabled = distance <= maxVisibleDistance end local connection connection = RunService.Heartbeat:Connect(function() updateCountdownVisibility() end) nearestField.AncestryChanged:Connect(function() if nearestField.Parent == nil then connection:Disconnect() end end) local countdownLabel = Instance.new("TextLabel") countdownLabel.Name = "CountdownLabel" countdownLabel.Size = UDim2.new(1, 0, 1, 0) countdownLabel.BackgroundTransparency = 1 countdownLabel.Font = Enum.Font.SourceSansBold countdownLabel.TextColor3 = Color3.new(1, 1, 1) countdownLabel.TextScaled = true countdownLabel.Parent = countdownGui local stage1GrowthTime = 5 local stage2GrowthTime = 5 local totalGrowthTime = stage1GrowthTime + stage2GrowthTime local carrotStage2 for i = totalGrowthTime, 1, -1 do UpdateCountdownEvent:FireAllClients(nearestField, i) wait(1) if i == stage1GrowthTime + 1 then carrotStage1:Destroy() carrotStage2 = Growth.CarrotStage2:Clone() setPartProperties(carrotStage2) carrotStage2.Parent = nearestField carrotStage2:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) end end carrotStage2:Destroy() local carrotStage3 = Growth.CarrotStage3:Clone() setPartProperties(carrotStage3) carrotStage3.Parent = nearestField carrotStage3:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) createCarrotProximityPrompt(nearestField, player) updateWateringIcons(player) countdownGui:Destroy() end end local function plantCorn(player) local profile = Manager.Profiles[player] if not profile then return end if profile.Data.CornSeeds < 1 then return end local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local nearestField, minDistance = nil, math.huge local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local distance = (humanoidRootPart.Position - field.PrimaryPart.Position).Magnitude if distance < minDistance then nearestField = field minDistance = distance end end if minDistance <= 10 then if nearestField.PrimaryPart:GetAttribute("IsWatered") ~= true then -- Check if the field is watered return end local cropStages = getCropStages(nearestField) -- use the helper function -- check if any crop stage exists in the field for _, stage in pairs(cropStages) do if stage then return end end Manager.AdjustCornSeeds(player, -1) local cornStage1 = Growth.CornStage1:Clone() setPartProperties(cornStage1) cornStage1.Parent = nearestField cornStage1:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) updateWateringIcons(player) local countdownGui = Instance.new("BillboardGui") countdownGui.Name = "CountdownGui" countdownGui.Size = UDim2.new(0, 50, 0, 50) countdownGui.StudsOffset = Vector3.new(0, 7, 0) countdownGui.Parent = nearestField local maxVisibleDistance = 20 local function updateCountdownVisibility() if not player.Character then return end local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local distance = (humanoidRootPart.Position - nearestField.PrimaryPart.Position).Magnitude countdownGui.Enabled = distance <= maxVisibleDistance end local connection connection = RunService.Heartbeat:Connect(function() updateCountdownVisibility() end) nearestField.AncestryChanged:Connect(function() if nearestField.Parent == nil then connection:Disconnect() end end) local countdownLabel = Instance.new("TextLabel") countdownLabel.Name = "CountdownLabel" countdownLabel.Size = UDim2.new(1, 0, 1, 0) countdownLabel.BackgroundTransparency = 1 countdownLabel.Font = Enum.Font.SourceSansBold countdownLabel.TextColor3 = Color3.new(1, 1, 1) countdownLabel.TextScaled = true countdownLabel.Parent = countdownGui local stage1GrowthTime = 5 local stage2GrowthTime = 5 local totalGrowthTime = stage1GrowthTime + stage2GrowthTime local cornStage2 for i = totalGrowthTime, 1, -1 do UpdateCountdownEvent:FireAllClients(nearestField, i) wait(1) if i == stage1GrowthTime + 1 then cornStage1:Destroy() cornStage2 = Growth.CornStage2:Clone() setPartProperties(cornStage2) cornStage2.Parent = nearestField cornStage2:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) end end cornStage2:Destroy() local cornStage3 = Growth.CornStage3:Clone() setPartProperties(cornStage3) cornStage3.Parent = nearestField cornStage3:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) createCornProximityPrompt(nearestField, player) updateWateringIcons(player) countdownGui:Destroy() end end local function plantTomato(player) local profile = Manager.Profiles[player] if not profile then return end if profile.Data.TomatoSeeds < 1 then return end local character = player.Character if not character then return end local humanoidRootPart = character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local nearestField, minDistance = nil, math.huge local CropField = getPlayerPersonalCropField(player) if not CropField then return end for _, field in ipairs(CropField:GetChildren()) do local distance = (humanoidRootPart.Position - field.PrimaryPart.Position).Magnitude if distance < minDistance then nearestField = field minDistance = distance end end if minDistance <= 10 then if nearestField.PrimaryPart:GetAttribute("IsWatered") ~= true then -- Check if the field is watered return end local cropStages = getCropStages(nearestField) -- use the helper function -- check if any crop stage exists in the field for _, stage in pairs(cropStages) do if stage then return end end Manager.AdjustTomatoSeeds(player, -1) local tomatoStage1 = Growth.TomatoStage1:Clone() setPartProperties(tomatoStage1) tomatoStage1.Parent = nearestField tomatoStage1:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) updateWateringIcons(player) -- Rest of the code local countdownGui = Instance.new("BillboardGui") countdownGui.Name = "CountdownGui" countdownGui.Size = UDim2.new(0, 50, 0, 50) countdownGui.StudsOffset = Vector3.new(0, 7, 0) countdownGui.Parent = nearestField local maxVisibleDistance = 20 local function updateCountdownVisibility() if not player.Character then return end local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart") if not humanoidRootPart then return end local distance = (humanoidRootPart.Position - nearestField.PrimaryPart.Position).Magnitude countdownGui.Enabled = distance <= maxVisibleDistance end local connection connection = RunService.Heartbeat:Connect(function() updateCountdownVisibility() end) nearestField.AncestryChanged:Connect(function() if nearestField.Parent == nil then connection:Disconnect() end end) local countdownLabel = Instance.new("TextLabel") countdownLabel.Name = "CountdownLabel" countdownLabel.Size = UDim2.new(1, 0, 1, 0) countdownLabel.BackgroundTransparency = 1 countdownLabel.Font = Enum.Font.SourceSansBold countdownLabel.TextColor3 = Color3.new(1, 1, 1) countdownLabel.TextScaled = true countdownLabel.Parent = countdownGui local stage1GrowthTime = 5 local stage2GrowthTime = 5 local totalGrowthTime = stage1GrowthTime + stage2GrowthTime local tomatoStage2 for i = totalGrowthTime, 1, -1 do UpdateCountdownEvent:FireAllClients(nearestField, i) wait(1) if i == stage1GrowthTime + 1 then tomatoStage1:Destroy() tomatoStage2 = Growth.TomatoStage2:Clone() setPartProperties(tomatoStage2) tomatoStage2.Parent = nearestField tomatoStage2:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) end end tomatoStage2:Destroy() local tomatoStage3 = Growth.TomatoStage3:Clone() setPartProperties(tomatoStage3) tomatoStage3.Parent = nearestField tomatoStage3:SetPrimaryPartCFrame(nearestField.PrimaryPart.CFrame) createTomatoProximityPrompt(nearestField, player) updateWateringIcons(player) countdownGui:Destroy() end end spawn(autoWaterFields) local function startWateringIconsUpdaterForAll() for _, player in ipairs(Players:GetPlayers()) do spawn(function() startWateringIconsUpdater(player) end) end end local function onPlayerAdded(player) startWateringIconsUpdater(player) end Players.PlayerAdded:Connect(onPlayerAdded) startWateringIconsUpdaterForAll() PlantWheatEvent.OnServerEvent:Connect(plantWheat) PlantPotatoEvent.OnServerEvent:Connect(plantPotato) PlantCarrotEvent.OnServerEvent:Connect(plantCarrot) PlantCornEvent.OnServerEvent:Connect(plantCorn) PlantTomatoEvent.OnServerEvent:Connect(plantTomato) WaterCanEvent.OnServerEvent:Connect(waterField) UpdateWaterEvent.OnServerEvent:Connect(onWaterAmountChanged)