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 6 years ago
local tree = script.Parent

function invisibletree()
    if tree.Timber.Value == 1 then
        tree.Leaves.CanCollide = false
        tree.Leaves.Transparency = 1
        tree.Trunk.CanCollide = false
        tree.Trunk.Transparency = 1
        wait(10)
        tree.Leaves.CanCollide = true
        tree.Leaves.Transparency = 0.011
        tree.Trunk.CanCollide = true
        tree.Trunk.Transparency = 0
        tree.Timber.Value = 0
        tree.hit.Value = 10
    end
end

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 6 years ago

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

local tree = script.Parent
local debounce = false
function invisibletree()
   if not debounce then
      if tree.Timber.Value == 1 then
         debounce = true
          tree.Leaves.CanCollide = false
          tree.Leaves.Transparency = 1
          tree.Trunk.CanCollide = false
          tree.Trunk.Transparency = 1
          wait(10)
          tree.Leaves.CanCollide = true
          tree.Leaves.Transparency = 0.011
          tree.Trunk.CanCollide = true
          tree.Trunk.Transparency = 0
          tree.Timber.Value = 0
          tree.hit.Value = 10
          debounce = false
        end
    end
end
tree.Timber.Changed:connect(invisibletree()) -- Runs whenever a value of Timber changes

0
Didn't work buddy but thx anyway :] dadysherwin2 155 — 6y
Ad
Log in to vote
0
Answered by 6 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.

local leaves = script.Parent.Leaves
local trunk = script.Parent.Trunk
local timber = script.Parent.Timber
local hit = script.Parent.hit

if timber.Value == 1 then
    leaves.Transparency = 1
    leaves.CanCollide = false
    trunk.Transparency = 1
    trunk.CanCollide = false
    wait(10)
    timber.Value = 0
    leaves.Transparency = 0
    leaves.CanCollide = true
    trunk.Transparency = 0
    trunk.CanCollide = true
    hit.Value = 10
end
local leaves = script.Parent.Leaves
local trunk = script.Parent.Trunk
local timber = script.Parent.Timber
local hit = script.Parent.hit

if timber.Value == 0 then
    leaves.Transparency = 0
    leaves.CanCollide = true
    trunk.Transparency = 0
    trunk.CanCollide = true
    hit.Value = 10

if timber.Value == 1 then
    leaves.Transparency = 1
    leaves.CanCollide = false
    trunk.Transparency = 1
    trunk.CanCollide = false
    wait(10)
    timber.Value = 0
end
0
Didn't work buddy e.e dadysherwin2 155 — 6y
0
That's weird, It definitely should have. Well, sorry about that. Skyraider5 -21 — 6y

Answer this question