Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Error after everything has been done correctly?

So this script is enabled when the plant is harvested and it waits till the set amount of days has passed in order to "regrow" itself.

    local Debounce = true

while true do wait()

local Day = workspace.Player_Cache.Day

if Day.Value == script.DayWhenCut.Value + 2 then print("Time Reached")

if Debounce == true then Debounce = false

local Replace = game.ServerStorage.Plant_Objects.Salad_Stick:Clone()

Replace.Parent = script.Parent.Parent.Parent.Parent.Parent

Replace.Salad_Stick.Position = script.Parent.Parent.Parent.Position

print("Plant Replaced")

Replace.Salad_Stick.ClickDetector.Harvest.Replacer.GrowsLeft.Value = script.GrowsLeft.Value - 1

script.Parent.Parent.Parent.Parent:Destroy()

end

end

end

(For some reason i cant paste my script into the code view so instead i have to do this, sorry about that)

Basically the whole script fires, everything fires and works perfectly and on the deletion of the model:

script.Parent.Parent.Parent.Parent:Destroy()

it displays this error: "DayWhenCut is not a valid member of Script" It doesn't effect the game but clogs up my output with fake errors.

4 comments

0

Your getting the error because of the deletion of the model.

0

I figured that out, i am asking if there is a way i can remove the model without the error.

0

I think DayWhenCut is not a valid member of script. Care to provide screenshot of the explorer?

0

I fixed the bug, sorry didn't see your message but you can see how i fixed it below.

2 answers

Hey try using a pcall function. What it does is it contains the errors and if anything goes wrong it wont break the script.

pcall(function()
	script.Parent.Parent.Parent.Parent:Destroy()
end)

1 comment

0

smh

After a few days i figured out how to fix it without suppressing an error here is the script:

local Debounce = true

local Off = false

  

while Off == false do wait()

local Day = workspace.Player_Cache.Day

if Day.Value == script.DayWhenCut.Value + 2 and script.GrowsLeft.Value >= 1 then print("Time Reached")

if Debounce == true then Debounce = false

local Replace = game.ServerStorage.Plant_Objects.Salad_Stick:Clone()

Replace.Parent = script.Parent.Parent.Parent.Parent.Parent

Replace.Salad_Stick.Position = script.Parent.Parent.Parent.Position

Replace.Salad_Stick_CutA.Position = script.Parent.Parent.Parent.Parent.CutA.Position

Replace.Salad_Stick_CutB.Position = script.Parent.Parent.Parent.Parent.CutB.Position

Replace.Salad_Stick_Stalk.Position = script.Parent.Parent.Parent.Parent.Salad_Stick_Stalk.Position

print("Plant Replaced")

Replace.Salad_Stick.ClickDetector.Harvest.Replacer.GrowsLeft.Value = script.GrowsLeft.Value - 1

script.Parent.Parent.Parent.Parent:Destroy()

Off = true

end

end

if Off == false and script.GrowsLeft.Value == 0 then

script.Parent.Parent.Parent.Parent.Salad_Stick_Stalk.ClickDetector.UnRoot.Disabled = false

script.Parent.Parent.Parent.Parent.Salad_Stick_Stalk.ClickDetector.MaxActivationDistance = 10

Off = true

end

end

The script is a bit different now but its the same premise, To fix the unwanted error i changed the while true do to while Off = false do, Whenever the script gets fully run it sets off to true which prevents the script sending the error out.

Hope someone else finds this useful :).

This discussion is preserved as it was. New answers, comments, and votes are closed.