Hey guys ive been dealing with this issue for 2 days and idk what to do
The issue is that the prompt doesnt want to trigger at all, it just doesnt work, and this is INSIDE A MODULE SCRIPT!!!
Code:
local PlantModule = {}
--helper
local function setStageVisible(stageModel, visible)
if not stageModel then return end
for _, obj in ipairs(stageModel:GetDescendants()) do
if obj:IsA("BasePart") then
obj.Transparency = visible and 0 or 1
obj.CanCollide = visible
obj.CanQuery = visible
end
end
end
-- GROWTH
function PlantModule.Grow(Plant)
print("growth started")
local stage1 = Plant:FindFirstChild("Stage1")
local stage2 = Plant:FindFirstChild("Stage2")
local stage3 = Plant:FindFirstChild("Stage3")
if not (stage1 and stage2 and stage3) then
warn("Missing stages in " .. Plant.Name)
return
end
for _, obj in ipairs(stage3:GetDescendants()) do
if obj:IsA("BasePart") then
obj.CanQuery = true
obj.CanCollide = true
obj.CanTouch = true
end
end
setStageVisible(stage1, false)
setStageVisible(stage2, false)
setStageVisible(stage3, false)
setStageVisible(stage1, true)
local growTime1 = Plant:GetAttribute("GrowTime1") or math.random(1, 3)
local growTime2 = Plant:GetAttribute("GrowTime2") or math.random(3, 5)
task.wait(growTime1)
setStageVisible(stage2, true)
task.wait(growTime2)
setStageVisible(stage3, true)
local part = stage3:WaitForChild("HarvestPart")
if part then
local harvestPrompt = part:FindFirstChildOfClass("ProximityPrompt")
if harvestPrompt then
harvestPrompt.Enabled = true
print("prompt enabled")
end
end
end
-- HARVEST
function PlantModule.SetUpPrompt(Plant)
local stage3 = Plant:FindFirstChild("Stage3")
if not stage3 then
warn("No Stage3 in " .. Plant.Name)
return
end
local harvestPart = stage3:FindFirstChild("HarvestPart")
if not harvestPart then
warn("No BasePart found in stage3 of " .. Plant.Name)
return
end
harvestPart.Anchored = true
harvestPart.CanQuery = true
harvestPart.Transparency = 1
-- prevent duplicates
--if harvestPart:FindFirstChildOfClass("ProximityPrompt") then return end
local harvestPrompt = Instance.new("ProximityPrompt")
harvestPrompt.Name = "HarvestPrompt"
harvestPrompt.ActionText = "Harvest"
harvestPrompt.ObjectText = Plant:GetAttribute("FruitType") or "Plant"
harvestPrompt.HoldDuration = 0
harvestPrompt.MaxActivationDistance = 10
harvestPrompt.RequiresLineOfSight = false
harvestPrompt.Enabled = false
harvestPrompt.Parent = harvestPart
print("Prompt added to " .. harvestPart:GetFullName()) -- DEBUG
print(harvestPrompt.Parent.Name)
harvestPrompt.Triggered:Connect(function(player)
--print("Prompt triggered by " .. player.Name)
local fruitType = Plant:GetAttribute("FruitType")
if not fruitType then
--warn("Missing FruitType attribute bruh")
return
end
--print("FruitType: ", fruitType)
local inventory = player:FindFirstChild("Inventory")
--print("Inventory: ", inventory)
if not inventory then
--warn("No inventory")
return
end
local fruit = inventory:FindFirstChild(fruitType)
--print("Fruit found: ", fruit)
if not fruit then
--warn("Missing fruit in inventory" .. fruitType)
return
end
fruit.Value += 1
Plant:Destroy()
--print("Harvesting was done right lol" .. fruitType)
end)
end
return PlantModule
Also this is where its being called, on SSS:
local plantModule = require(game.ServerScriptService:WaitForChild("Modules").PlantModule)
local plantsFolder = game.Workspace:WaitForChild("Plants")
local function setupPlant(Plant)
--start growth
task.spawn(function()
plantModule.Grow(Plant)
print("Finished growing " .. Plant.Name)
end)
-- setup harvesting
plantModule.SetUpPrompt(Plant)
print("prompt setup and harvested")
end
-- exisiting plants
for _, plant in ipairs(plantsFolder:GetChildren()) do
if plant:IsA("Model") then
setupPlant(plant)
end
print("plant model found")
end
-- new plants
plantsFolder.ChildAdded:Connect(function(Plant)
if Plant:IsA("Model") then
setupPlant(Plant)
end
print("plants added to folder")
end)
Could i get some help, ive tried almost everything!