Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

1 comment

0

Mark the answer as answered if it helped you

3 answers

✓ Accepted answer

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!

2 comments

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?

0

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

0

There are couple errors on your code. Please recheck before posting an answer

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.

0

Nope. Recheck your code. There is bigger problems than the one you mentioned

0

Enlightin me please. What have I done wrong?

0

^ Read my post

0

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.