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

Why is my door not opening?

Asked by 10 years ago

The biggest problem here is that now when ever I touch my door it wont CanCollide = false. What I am trying to do here is make the door so that when part is touched, it will no longer collide and part2 will become green. And when you stop touching the door part2 becomes red. I need help pointing out what went wrong because I am very new at scripting. Thanks for help in advance!

local Base = game.Workspace.Parts
local Colors = game.Workspace.Parts

function onTouched (hit)
    Base.Transparency = .5
    Base.CanCollide = false
end

script.Parent.Touched:connect(onTouched)

if script.Parent.Touched:connect(onTouched) == false then
    Base.Transparency = 0
    Base.CanCollide = true
end

if Base.CanCollide == false then
    Colors.BrickColor = BrickColor.new ("Bright green")
end

if Base.CanCollide == true then
    Colors.BrickColor = BrickColor.new ("Bright red")
end

0
What is 'Parts' referring to? Redbullusa 1580 — 10y
0
Parts is the Physical name of the brick. I didnt want to put part2 cause it would confuse me so I put an "s" at the end noob1126 34 — 10y
0
And are both variables referring to the same "Parts"? Redbullusa 1580 — 10y
0
No in workspace there is "Part" and "Parts" and Part is suppose to be the door and "Parts" is supposed to be the color changing brick. noob1126 34 — 10y
0
If 'Base' is the door part, then change 'game.Workspace.Parts' to 'game.Workspace.Part'. The program will pick the same "Parts" from your variables if you assigned them as such. Redbullusa 1580 — 10y

1 answer

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

Make two separate functions.

Base = game.Workspace.Part
Colors = game.Workspace.Parts

--function onTouched(hit)

--end

--function onTouchEnded(hit)

--end
-- I'm using the comment feature to highlight the things that are added on to the script.

Make 2 connection lines for those functions.

Base = game.Workspace.Part
Colors = game.Workspace.Parts

function onTouched(hit)

end

function onTouchEnded(hit)

end

--script.Parent.Touched:connect(onTouched)
--script.Parent.TouchEnded:connect(onTouchEnded)

Fill in your code.

Base = game.Workspace.Part
Colors = game.Workspace.Parts

function onTouched(hit)
--  Base.Transparency = .5
--  Base.CanCollide = false
--  Colors.BrickColor = BrickColor.new("Bright green")
end

function onTouchEnded(hit)
--  Base.Transparency = 0
--  Base.CanCollide = true
--  Colors.BrickColor = BrickColor.new("Bright red")
end

script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(onTouchEnded)

Utilize the 'hit' argument if you don't want a random part to touch the parent of script.

Base = game.Workspace.Part
Colors = game.Workspace.Parts

function onTouched(hit)
--  if (hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")) then
        Base.Transparency = .5
        Base.CanCollide = false
        Colors.BrickColor = BrickColor.new("Bright green")
--  end
end

function onTouchEnded(hit)
--  if (hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")) then
        Base.Transparency = 0
        Base.CanCollide = true
        Colors.BrickColor = BrickColor.new("Bright red")
--  end
end

script.Parent.Touched:connect(onTouched)
script.Parent.TouchEnded:connect(onTouchEnded)

If "Base" is the door, and you want the player to touch the door to activate its functions, you can do this if the script is in another location.

Base.Touched:connect(onTouched)
Base.TouchEnded:connect(onTouchEnded)

There's this amazing thing called a "Model." It's an object that can group things together, so they'd be relatively separate from other objects in terms of scripting. I would recommend grouping all of the parts that have anything to do with the door such as the indicator and the door part. Doing so will help in terms of organization.

If you do that, you can also set the script to be in the model and adjust your variables so it would be like this:

Base = script.Parent.Part
Colors = script.Parent.Parts

That way your script will access to your parts internally (from the scripts' point of view) rather than externally (from the game's point of view).

Ad

Answer this question