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

How do I make a part activate another part's code ontouch?

Asked by 6 years ago

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?

0
Mark the answer as answered if it helped you Axceed_Xlr 380 — 6y

3 answers

Log in to vote
1
Answered by 6 years ago

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 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, the baseplate Hence, 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 Humanoid part touches the brick. For our case, the Local Player

Have a lovely day of coding!
0
^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? HimoutoUmaruDomaChan 20 — 6y
0
The code will work fine if you just rename it. Axceed_Xlr 380 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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)
0
There are couple errors on your code. Please recheck before posting an answer Axceed_Xlr 380 — 6y
0
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. TheLightningRises 56 — 6y
0
Nope. Recheck your code. There is bigger problems than the one you mentioned Axceed_Xlr 380 — 6y
0
Enlightin me please. What have I done wrong? TheLightningRises 56 — 6y
View all comments (2 more)
0
^ Read my post Axceed_Xlr 380 — 6y
0
Oh, I'm sorry I was tired, thank you for correcting me. TheLightningRises 56 — 6y
Log in to vote
-1
Answered by
ZenTGE 4
6 years ago

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!

Answer this question