Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make parts invisible and uncollidable via values?

Asked by 7 years ago
01local tree = script.Parent
02 
03function invisibletree()
04    if tree.Timber.Value == 1 then
05        tree.Leaves.CanCollide = false
06        tree.Leaves.Transparency = 1
07        tree.Trunk.CanCollide = false
08        tree.Trunk.Transparency = 1
09        wait(10)
10        tree.Leaves.CanCollide = true
11        tree.Leaves.Transparency = 0.011
12        tree.Trunk.CanCollide = true
13        tree.Trunk.Transparency = 0
14        tree.Timber.Value = 0
15        tree.hit.Value = 10
16    end
17end

This script is inside a tree. Trunk and Leaves are both parts and Timber and hit are both IntValues. I am trying to make it so that whenever the Timber value ever goes to 1 then every physical thing on the tree will go fully transparent and cannot be collided with anything else and after 10 seconds, it would return to normal with the Timber value back at 0 and the hit value at 10 I made a script but it isn't working. Can someone help make it work? I am not that good at scripting.

Explorer Hirachy - 1 Game 2 Workspace 3 Tree 4 Script 4 Timber 4 hit 4 Leaves 4 Trunk

There are no children in Script, Timber, hit, Leaves or Trunk.

Thanks for your time.

2 answers

Log in to vote
0
Answered by 7 years ago

Just got to call the function at some point. And, I would add a debounce, to avoid errors.

01local tree = script.Parent
02local debounce = false
03function invisibletree()
04   if not debounce then
05      if tree.Timber.Value == 1 then
06         debounce = true
07          tree.Leaves.CanCollide = false
08          tree.Leaves.Transparency = 1
09          tree.Trunk.CanCollide = false
10          tree.Trunk.Transparency = 1
11          wait(10)
12          tree.Leaves.CanCollide = true
13          tree.Leaves.Transparency = 0.011
14          tree.Trunk.CanCollide = true
15          tree.Trunk.Transparency = 0
View all 22 lines...
0
Didn't work buddy but thx anyway :] dadysherwin2 155 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

I think part of the problem might be that your script has timber's value getting set back to zero after the other stuff is set back to normal, I'm not sure but that might be the case. I don't know for sure because I haven't seen all about your game but I also don't think you need the whole function invisible tree() thing, as long as the script knows what to do if timber's value equals zero you should be good. I could be wrong but I think an overall issue is that you made it a bit more complex than it had to be because, in reality, it is a fairly straightforward script. Given all of that, the script I wrote below should work. If it doesn't then you can just comment below and I'll try to fix it to the best of my ability. Good Luck :)

IMPORTANT: There are two scripts below, try the first one, it should work but if it doesn't then go ahead and try the second one. If THAT doesn't work then comment below and I will try to figure out what is wrong.

01local leaves = script.Parent.Leaves
02local trunk = script.Parent.Trunk
03local timber = script.Parent.Timber
04local hit = script.Parent.hit
05 
06if timber.Value == 1 then
07    leaves.Transparency = 1
08    leaves.CanCollide = false
09    trunk.Transparency = 1
10    trunk.CanCollide = false
11    wait(10)
12    timber.Value = 0
13    leaves.Transparency = 0
14    leaves.CanCollide = true
15    trunk.Transparency = 0
16    trunk.CanCollide = true
17    hit.Value = 10
18end
01local leaves = script.Parent.Leaves
02local trunk = script.Parent.Trunk
03local timber = script.Parent.Timber
04local hit = script.Parent.hit
05 
06if timber.Value == 0 then
07    leaves.Transparency = 0
08    leaves.CanCollide = true
09    trunk.Transparency = 0
10    trunk.CanCollide = true
11    hit.Value = 10
12 
13if timber.Value == 1 then
14    leaves.Transparency = 1
15    leaves.CanCollide = false
16    trunk.Transparency = 1
17    trunk.CanCollide = false
18    wait(10)
19    timber.Value = 0
20end
0
Didn't work buddy e.e dadysherwin2 155 — 7y
0
That's weird, It definitely should have. Well, sorry about that. Skyraider5 -21 — 7y

Answer this question