✓ Accepted answer
Make two separate functions.
Base = game.Workspace.Part
Colors = game.Workspace.Parts
Make 2 connection lines for those functions.
Base = game.Workspace.Part
Colors = game.Workspace.Parts
function onTouched(hit)
end
function onTouchEnded(hit)
end
Fill in your code.
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)
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)
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)
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).
5 comments
What is 'Parts' referring to?
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
And are both variables referring to the same "Parts"?
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.
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.