I will try my best to be very descriptive to explain this. I am making a model, in which a player steps on a button (the soil itself) and a seed slowly becomes transparent with a for loop. After the seed is "gone", the player will step on it again and a sprout will slowly appear. Think of the common button you see in games which spawns a car. Instead of a spawn button, the goal of this model is to be an interactive garden/planter. Got that?
This is the code I tried out:
01 | debounce = true |
02 | script.Parent.Touched:connect( function (x) |
03 | x.Parent:FindFirstChild( "Humanoid" ) |
04 | if game.Workspace.Seed.Transparency = = 0 then debounce = true |
05 | for i = 0 , 1 , 0.01 do |
06 | game.Workspace.Seed.Transparency = i |
07 | wait( 0.1 ) |
08 |
09 | end |
10 | end |
11 | end ) |
12 | if game.Workspace.Seed.Transparency = = 1 then |
13 | for m = 1 , 0 ,- 0.01 do --What I replaced |
14 | game.Workspace.Sprout.Transparency = m --What I replaced |
15 | end |
The script doesn't do anything! It was not successful even when I replaced the small section of the code above with Print("Hello")
. It also did ** not** work when I replaced it with game.Workspace.Sprout.Transparency = 0
. What is the problem? Does it not accept two for loops or what? What can I do to fix it?
I'm new to scripting still, but if I'm not mistaken, you're second for loop needs to have a "-" before 0.01
1 | for m = 1 , 0 ,- 0.01 do |
If you're going to subtract, you should put a negative sign. Hope I helped, and if I didn't, sorry.
you need TWO equal marks for a if statement. This is incorrect.
1 | if game.Workspace.Seed.Transparency = = 0 then debounce = true |
How do we fix it? With a handy thing called common sense! Like this
1 | if game.Workspace.Seed.Transparency = = 0 and debounce = = true then -- yay it works |
But wait, we have to make sure that the touched thing is a player! So we need this.
1 | if hit.Parent:FindFirstChildOfClass( "Humanoid" ) then |
Also, in your question you said a property without a equal sign before the value. Just a reminder. So this should be the finished product! Also, I never learned for loops.
01 | local debounce = true |
02 | script.Parent.Touched:connect( function (x) |
03 | x.Parent:FindFirstChild( "Humanoid" ) |
04 | if game.Workspace.Seed.Transparency = = 0 and debounce = = true and x.Parent:FindFirstChildOfClass( "Humanoid" ) then |
05 | local debounce = false --Whats the point of a debounce if it never turns something else! |
06 | for i = 0 , 1 , 0.01 do |
07 | game.Workspace.Seed.Transparency = i |
08 | wait( 0.1 ) |
09 | end |
10 | local debounce = true --Makes it able to work again and not be a junk script |
11 | end |
12 | end ) |
13 | if game.Workspace.Seed.Transparency = = 1 then |
14 | for m = 1 , 0 ,- 0.01 do |
15 | game.Workspace.Sprout.Transparency = m |
16 | end --Edited |
17 | end |