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

How do I fix this click-door script?

Asked by 9 years ago
script.Parent.Value = 0
local H = script.Parent.Value
function onClicked()
if H == 0 then
    wait(1)
    off()
else
    on()
end
end 

function off()
    wait(.1)
    script.Parent.Parent.Part2.CanCollide = false
    wait(.1)
    script.Parent.Parent.Part2.Transparency = 1
    H = 1
end

function on() 
    wait(.1)
    script.Parent.Parent.Part2.CanCollide = true
    wait(.1)
    script.Parent.Parent.Part2.Transparency = 0
    H = 0
end

script.Parent.Parent.Part2.ClickDetector.MouseClick:connect(onClicked)


It is supposed to open/close by a click but it won't work. Why?

4 answers

Log in to vote
0
Answered by 9 years ago

Eh.. I can't really understand the script your using, so I'll use my own kind of script, I hope it helps;

debounce=true
function OpenClose()
if debounce then
debounce=false
script.Parent.Transparency=1
script.Parent.CanCollide=false

wait(2)
debounce=true
script.Parent.Transparency=0
script.Parent.CanCollide=true
end end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope this helped!

Ad
Log in to vote
0
Answered by
User#2 0
9 years ago

The problem is in the line where you assign the H variable.

What you're currently doing is saying "Assign H to be script.Parent's current Value" then later saying "Set H (Not script.Parent's Value property) to 1/0".

This has to do with how variables work. When you assign H to script.Parent.Value you're actually assigning it to whatever the value currently is, not the property itself. So later when you change the variable, that's all you're doing, changing the variable, not the value.

To fix this, just assign H to script.Parent and whenever you were doing something with H before, now just do H.Value.

Log in to vote
0
Answered by 9 years ago

In this part of code:

script.Parent.Value = 0
local H = script.Parent.Value

If you're trying to set the value of "H" then use:

local H=0

If you're trying to get script.Parent's Value then do:

script.Parent.Value = 0
local H = script.Parent

And change "H" to "H.Value" then your Value will be updated because if you do:

local H = script.Parent.Value -- This value is defined as a number and not an Instance. 

It'll save it's currently value to the variable "H", so it'll not change script.Parent's Value anymore.

Sorry, for my bad grammar, I hope I help.

And don't forget to add wait(1) to the starting, so you're sure it sets your variable properly.

Log in to vote
-2
Answered by 9 years ago

Wherever it's Part2, make it, and the Parent before it, like this :

Parent["Part2"]

Answer this question