So I am creating a script for an interactive garden. If the player steps on the soil which contains a seed on top, the seed dissolves. When a player walks on it once again, a sprout slowly appears. I did that part successfully using two debounce variables.
But I want to continue the script. If the player walks across the soil which now contains the sprout, the sprout will dissolve and a flower will bloom in place.
This is the script so far:
01 | debounce = false |
02 | rebounce = false |
03 | mbounce = false |
04 | script.Parent.Soil.Touched:connect( function () |
05 |
06 | if not debounce then |
07 |
08 | debounce = true |
09 |
10 | for i = 0 , 1 , 0.1 do |
11 | script.Parent.Seed.Transparency = i |
12 | wait ( 0.1 ) |
13 | end |
14 | wait( 20 ) |
15 | debounce = false |
How come when I use the "Destroy" Instance, it doesn't work at all?
Also, I want to do the for loop to get rid of the sprout, so it can appear to dissolve. But, when I did the for loop with a separate debounce variable, it did not work at all.
I like your idea. Upvoted. Now, in this kind of script, I would suggest you a situation variable, like...
1 | local Situation = "Nothing" |
When touched is fired, put an if condition and do seeding process.
1 | if Situation = = "Nothing" then |
2 | --Seeding process |
3 | Situation = "Seed" |
4 | end |
And same for others, but you have to use Elseif for this.
01 | if Situation = = "Nothing" then |
02 | --Seeding process |
03 | Situation = "Seed" |
04 | elseif Situation = = "Seed" then |
05 | --Sprouting process? I am not good at flowers |
06 | Situation = "SproutOff" |
07 | elseif Situation = = "SproutOff" then |
08 | --Sprouting now??? |
09 | Situation = "SproutOn" |
10 | end |
And if we get all those things together...
01 | local Debounce = false |
02 | local Situation = "Nothing" |
03 |
04 | script.Parent.Soil.Touched:connect( function () |
05 | if Debounce = = false then |
06 | Debounce = true |
07 |
08 | if Situation = = "Nothing" then |
09 | --Seeding process |
10 | elseif Situation = = "Seed" then |
11 | --Sprouting process? I am not good at flowers |
12 | Situation = "SproutOff" |
13 | elseif Situation = = "SproutOff" then |
14 | --Sprouting now??? |
15 | Situation = "SproutOn" |
16 | end |
17 |
18 | Debounce = false |
19 | end |
20 | end |
Please consider adding wait
lines inside if statements. Putting them outside would confuse you, I think...
Edit: Use destroy inside function if you want to destroy something.
Did this help you? Then please upvote and accept as an answer. (Please upvote, I need those :'( )
This is disappointing, superalp beat me to it, oh well, I spent a lot of time on this so I'll share anyways lol
01 | local debounce = false |
02 | local seedUsed = false |
03 | local sproutGrowing = false |
04 | local flowerBloomed = false |
05 | local goal = { } |
06 |
07 | local function TweenPart(part, Time, goal) |
08 | game:GetService( "TweenService" ):Create(part, TweenInfo.new(Time), goal):Play() |
09 | end |
10 |
11 | script.Parent.Soil.Touched:Connect( function () |
12 | if not debounce then |
13 | debounce = true |
14 |
15 | if not seedUsed then |
Your system with multiple debounces was going in the right direction, but just made everything confusing, so I made this use variables to help determine which "phase" of growth the plant is in.
Also, I converted your for i = #, #, # loop to animate into TweenService, which makes it look a lot smoother, and removes some math to make it easier.