Hey, devs! I’m currently having a problem with my script. It’s supposed to check if the player has sowed and watered their seeds, it makes a countdown and makes their plant visible, as well as able to be harvested.
I will try to explain the problem as best as possible: Player 1 has sowed their seeds and is starting to water them. At the same time, Player 2 leaves the game. This breaks the script and doesn’t make the countdown visible.
There are no errors in the output. The Sowed and Watered value are set to true.
Also, I’d like to add that I’m still learning to script, so I am not as advanced. This is only a part of the script since I feel like the error is around the while loop line.
local growtime = script.Parent.SETTINGS.GrowTime.Value
local location = script.Parent.GrownPlant
local seedlocation = script.Parent.Seeds
local harvestprompt = script.Parent.GrownPlant.plant.Harvest
while wait(0.5) do
if script.Parent.Sowed.Value == true and script.Parent.Watered.Value == true then
for _, player in game.Players:GetChildren() do
if player.SectionsNStuff.Section.Value == 1 then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785) then
if script.Parent.Sowed.Value == true and script.Parent.Watered.Value == true then
script.Parent.Sowed.Value = false
script.Parent.Watered.Value = false
local textLabel = script.Parent.BillboardGui.Text
local function CountDown()
local TIMER = 10
repeat
textLabel.Text = TIMER.."s"
wait(1)
TIMER -= 1
until TIMER <= 0
textLabel.Text = ""
end
CountDown()
local growtime = script.Parent.SETTINGS.GrowTime.Value
local location = script.Parent.GrownPlant
local seedlocation = script.Parent.Seeds
local harvestprompt = script.Parent.GrownPlant.plant.Harvest
local function CountDown(textLabel)
local TIMER = 10
repeat
textLabel.Text = TIMER.."s"
wait(1)
TIMER -= 1
until TIMER <= 0
textLabel.Text = ""
end
script.Parent.Sowed.Changed:Connect(function(newValue)
if newValue == true and script.Parent.Watered.Value == true then
for _, player in ipairs(game.Players:GetPlayers()) do
if player.SectionsNStuff.Section.Value == 1 then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785) then
script.Parent.Sowed.Value = false
script.Parent.Watered.Value = false
local textLabel = script.Parent.BillboardGui.Text
CountDown(textLabel)
end
end
end
end
end)
local GrowTime = script.Parent.SETTINGS.GrowTime.Value
local sowed = script.Parent.Sowed
local watered = script.Parent.Watered
local billboardGui = script.Parent.BillboardGui
local function Countdown(textLabel)
local timer = 10
repeat
textLabel.Text = timer .. "s"
wait(1)
timer = timer - 1
until timer <= 0
textLabel.Text = ""
end
sowed.Changed:Connect(function(newValue)
if newValue == true and watered.Value == true then
for _, player in ipairs(game.Players:GetPlayers()) do
if player.SectionsNStuff and player.SectionsNStuff.Section and player.SectionsNStuff.Section.Value == 1 then
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785) then
sowed.Value = false
watered.Value = false
local textLabel = billboardGui.Text
Countdown(textLabel)
end
end
end
end
end)
removed unused variables: growtime location seedlocation
assigned sowed and watered
renamed function
and added nil check
Nope, it doesn’t work again. I also realized the scripts don’t work even without a player leaving.
Is this the problem? I’ve tried using Changed on booleans before but it gave me an error in the output, but now it doesn’t show anything?
local GrowTime = script.Parent.SETTINGS.GrowTime.Value
local Sowed = script.Parent.Sowed
local Watered = script.Parent.Watered
local BillboardGui = script.Parent.BillboardGui
-- Adding debug prints
print("Script loaded.")
local function Countdown(textLabel)
local timer = 10
repeat
textLabel.Text = timer .. "s"
wait(1)
timer = timer - 1
until timer <= 0
textLabel.Text = ""
end
-- Event triggered when Sowed value changes
Sowed.Changed:Connect(function(newValue)
print("Sowed value changed to:", newValue)
-- Ensure the change is made correctly
if newValue == true and Watered.Value == true then
-- Iterate over all players
for _, player in ipairs(game.Players:GetPlayers()) do
-- Check the player's relevant section
if player.SectionsNStuff and player.SectionsNStuff.Section and player.SectionsNStuff.Section.Value == 1 then
-- Check if the player owns a specific game pass
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785) then
-- Reset Sowed and Watered values
Sowed.Value = false
Watered.Value = false
-- Get the TextLabel and start the countdown
local textLabel = BillboardGui.Text
Countdown(textLabel)
end
end
end
end
end)
This is what it printed: Script loaded. Sowed value changed to: true
Countdown does not appear.
I changed it from Sowed.Changed to Watered.Changed and it worked when a player isn’t leaving.
When another player left however, it stopped working once again.
This is how I updated the script:
local GrowTime = script.Parent.SETTINGS.GrowTime.Value
local Sowed = script.Parent.Sowed
local Watered = script.Parent.Watered
local BillboardGui = script.Parent.BillboardGui
-- Adding debug prints
print("Script loaded.")
local function Countdown(textLabel)
local timer = 10
repeat
textLabel.Text = timer .. "s"
wait(1)
timer = timer - 1
until timer <= 0
textLabel.Text = ""
end
-- Event triggered when Sowed value changes
Watered.Changed:Connect(function(newValue)
print("Watered value changed to:", newValue)
-- Ensure the change is made correctly
if newValue == true and Sowed.Value == true then
-- Iterate over all players
for _, player in ipairs(game.Players:GetPlayers()) do
-- Check the player's relevant section
if player.SectionsNStuff and player.SectionsNStuff.Section and player.SectionsNStuff.Section.Value == 1 then
-- Check if the player owns a specific game pass
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785) then
-- Reset Sowed and Watered values
Sowed.Value = false
Watered.Value = false
-- Get the TextLabel and start the countdown
local textLabel = BillboardGui.Text
Countdown(textLabel)
end
end
end
end
end)
local GrowTime = script.Parent.SETTINGS.GrowTime.Value
local Sowed = script.Parent.Sowed
local Watered = script.Parent.Watered
local BillboardGui = script.Parent.BillboardGui
-- Function to start countdown
local function Countdown(textLabel)
local timer = 10
repeat
textLabel.Text = timer .. "s"
wait(1)
timer = timer - 1
until timer <= 0
textLabel.Text = ""
end
-- Event handler for changes in Watered value
Watered.Changed:Connect(function(newValue)
print("Watered value changed to:", newValue)
-- Check if Watered is true and Sowed is also true
if newValue == true and Sowed.Value == true then
-- Iterate over all players
for _, player in ipairs(game.Players:GetPlayers()) do
-- Check if the player's section is relevant (assuming SectionsNStuff is correct)
if player.SectionsNStuff and player.SectionsNStuff.Section and player.SectionsNStuff.Section.Value == 1 then
-- Check if the player owns a specific game pass
local success, ownsGamePass = pcall(function()
return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 791599785)
end)
if success and ownsGamePass then
-- Reset Sowed and Watered values
Sowed.Value = false
Watered.Value = false
-- Get the TextLabel and start the countdown
local textLabel = BillboardGui.Text
Countdown(textLabel)
else
print("Error checking game pass ownership for player:", player.Name)
end
end
end
end
end)