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?
How do I make a part activate another part's code ontouch?
3 answers
Hi, FrostandFireGaming. I will be helping you regarding the question, "How do I make a part activate another part's code ontouch?"
Now this question has technically been answered by @TheArcticTerminal however his code results in bigger errors. When you run his code, you see something you don't want it to happen
The
Touchedevent does not only activate when a player touches a part. It also activates when a part is touched by another part, in this case, thebaseplateHence, the part will already be transparent when you press play.
A fix to this is simple.
-- 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
What I did differently
Humanoid property is inside every player's character. A normal parts do not own one. Hence, the code will not run until a
Humanoidpart touches the brick. For our case, theLocal Player
Have a lovely day of coding!
2 comments
^So do I re-name the parts to the names in the script and do I insert the declaration that arctic used before this code?
The code will work fine if you just rename it.
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)
6 comments
There are couple errors on your code. Please recheck before posting an answer
There is one mistake, and honestly that isn't the point of the statement. I think the owner of this question is more than capable to find out the error.
Nope. Recheck your code. There is bigger problems than the one you mentioned
Enlightin me please. What have I done wrong?
^ Read my post
Oh, I'm sorry I was tired, thank you for correcting me.
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Mark the answer as answered if it helped you