Changing property to a part when a certain part touches it

This is my first post on the Dev forum so I’m sorry if it is a bit hard to understand, or isn’t formatted correctly or something, anyways.

I’m a early intermediate level scripter and am trying to make a simple game to practice, but I’m currently stuck with trying to change a property to a part, but only when a specific part touches it. For example, when Part1 touches Part2 the script will check if Part2’s attribute value is less, if it is it will then unanchor Part2, but I only want this to happen if its Part1 that touches Part2. I’m currently only able to make to make it so that Part2 is unanchored no matter what touches it. Any help will be appreciated!

I have also been unable to find anything on this, on the dev forum or youtube.

1 Like

if you have a specific Name for the Part1 you can do in the start of the Touched function
if toucher.Name ~= "Part1Name" then return end

I think this is what you’re trying to go for? Make sure to adjust the part names and attribute values according to your actual set up.

local Part1 = workspace.Part1
local Part2 = workspace.Part2
local attributeValue = 10 --replace with your actual attribute value

-- handle the touch event
local function onPart2Touched(otherPart)
    -- check if the touching part is Part1
    if otherPart == Part1 then
        local currentAttributeValue = Part2:GetAttribute("attributeValue") -- attribute value of Part2
        if currentAttributeValue and currentAttributeValue < attributeValue then -- compare the attribute value
            Part2.Anchored = false -- and finally, unanchor Part2

-- connect the touch event to the function

Thank you! It works exactly how I need it too! I made a few tweaks and it works perfectly for what I need!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.