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

How can I get this door to move when these the value is a certain value?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

When I press the buttons, the value will get bigger and won't decrease, if the value is larger, then the door won't open? Help? Door script

-- Varibles
local light = script.Parent.Light
local openlight = light.Open
local closelight = light.Close
local door = script.Parent.Door
local buttonpressed = script.Parent.TotalPressed
function teamwork()
 if buttonpressed.Value <= 2 then
    closelight.Enabled = false
    light.BrickColor = BrickColor.new("Lime green")
    openlight.Enabled = true
door.Transparency = 0
door.Cancollide = false
end
wait(3)
door.Transparency = 1
door.Cancollide = true
    closelight.Enabled = true
    light.BrickColor = BrickColor.new("Really red")
    openlight.Enabled = false
end

Button script

local pressed = script.Parent.Parent.TotalPressed
function onPressed(hit)
 if hit.Parent:findFirstChild("Humanoid") and hit.Parent.Humanoid.Health ~= 0 then
pressed.Value = pressed.Value + 1
script.Parent.BrickColor = BrickColor.new("Really red")
else
pressed.Value = pressed.Value - 1
script.Parent.BrickColor = BrickColor.new("Lime green")
if pressed.Value < 0 then
pressed.Value = 0
end
end
end
script.Parent.Touched:connect(onPressed)

No errors in output If you can, explain why it won't work so I'll know why it's wrong?

1 answer

Log in to vote
0
Answered by 8 years ago

the reason why you are not getting the outcome you want is because you want to have Clicked Detectors instead of trying to find value. an example of a ClickDetector is a simple CanCollide door

local part = script.Parent
g = true

function open()
    g = false
    part.CanCollide = g
    end
function close()
        g  = true
        part.CanCollide = g
end
function OnClicked()
    if g == true then open() else close() end
end


script.Parent:WaitForChild("ClickDetector").MouseClick:connect(OnClicked)


here we can easy label g as door, and continue on. Anyways, from this idea you should realize that instead of a door, it can be a light. The awesome part with this is the idea that you can add more effects to the opening and closing. Yet, if you do not want to have a Click Detector, you can use on hit values if Humanoid touches wall or in your case light. Personally you can either have bricks with onhit values, or you can have a Click Detector. Since you are using lights, the best feature is onhit, and what you forgot to add is a Debounce boolean.

Ad

Answer this question