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

How do i make when a certain block touches another block it activates something?

Asked by 8 years ago

i tried onTouch but it also does it for the player also.

0
Add an if to your onTouch that checks the part name GoldenPhysics 474 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago
local function PartTouched(TouchedPart)
    print(TouchedPart.Name .. " has touched " .. Part.Name)
end

Part.Touched:connect(PartTouched)

This is probably what you have so far, if you want to check the the part touching is not a player, then you must add conditions to it.

local function PartTouched(TouchedPart)
    local Player = Game.Players:GetPlayerFromCharacter(TouchedPart.Parent)
    if Player == nil then
        print(TouchedPart.Name .. " has touched " .. Part.Name)
    end
end

Part.Touched:connect(PartTouched)

As you see here we're checking if the touched part is a character or not by using :GetPlayerFromCharacter() which will return the Player or Nil (Allowing us to check that it is indeed a character or not)

0
thanks bossay123 45 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Use this. It will check if the name is equal to the part that it needs to activate;

script.Parent.Touched:connect(function(hit) --assuming the script is inside the part that will get hit. (change it to where ever the part is)
    if hit.Name=="PartThatItNeedsToActivate" then
        --code
    end
end)

Answer this question