I don't know if this is possible, but for an example: A button that, when it's touched, makes another part disappear or become non-collidable. Can someone please explain and help me with this concept, or lead me to a page in the wiki that explains this?
The
Touched
event does not only activate when a player touches a part. It also activates when a part is touched by another part, in this case, thebaseplate
Hence, the part will already be transparent when you press play.
-- Declaration Section --//Game Services local Workspace = game:GetService("Workspace") --//Part Locations local ClickPart = Workspace:FindFirstChild("ClickPart") --Touching Part local ChangingPart = Workspace:FindFirstChild("ChangingPart") --Changing Part -- Processing Section local function changingPartsProperties (Hit) --Creating function [The `Hit` is a parameter which tells us `What touched the part?` local Character = Hit.Parent local Humanoid = Character:FindFirstChild("Humanoid") --Checking if what hit the part has a humanoid if Humanoid then --If humanoid is found then.... print("Changing Properties") ChangingPart.Transparency = 0.5 ChangingPart.CanCollide = false end end --Connecting Section ClickPart.Touched:Connect(changingPartsProperties) --Connecting `Touched` event
Humanoid property is inside every player's character. A normal parts do not own one. Hence, the code will not run until a
Humanoid
part touches the brick. For our case, theLocal Player
This could be done using a simple Touched
event.
For example.
part = workspace.part otherPart = workspace.part part.Touched:connect(function() otherPart.Transparency = 0.5 end)
Or, in this case you would want a button so, in a part, insert a ClickDetector
.
button = workspace.part:WaitForChild("ClickDetector") part = workspace.part part.CanCollide = false button.MouseButton1Click:connect(function() part.CanCollide = true wait(5) part.CanCollide = False end)
You'll have to make both parts a parent of a script, one being the child of the other. I've made key card doors like this. All you have to do is do script.parent.parent. Hope this helps!