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

How do you make a script that checks if something is touching another brick?

Asked by 6 years ago
Edited 6 years ago

How would you make something that, when clicked, checks if one brick is touching another brick, then does what the script says? Would it be like,

script.Parent.ClickDetector.mouseClick:connect(function()
    if function onTouched(hit) then
    --script
    else 
    -- script
end)

script.Parent.Touched:connect(onTouched)

I want the onTouched(hit) to be, if object 1 is touching object 2, then run the script. If object 1 isn't touching object 2, then run a different script. Any help would be appreciated.

I'm currently using the script

script.Parent.ClickDetector.mouseClick:connect(function()
    script.Parent.Parent.B3.AlignPosition.Enabled = false
    wait(.5)
    script.Parent.Parent.B3.AlignPosition.Enabled = true
    wait(.5)
    script.Parent.Parent.B3.AlignPosition.Enabled = false
    wait(.5)
    script.Parent.Parent.B3.AlignPosition.Enabled = true
    wait(.5)
    script.Parent.Parent.B3.AlignPosition.Enabled = false
end)

B3 being the object that is moving.

1 answer

Log in to vote
0
Answered by
arshad145 392 Moderation Voter
6 years ago
Edited 6 years ago

This is as far as I can help as your "objects" and "scripts" you want are unknown... Hope this is helpful.

local clicked = false
script.Parent.ClickDetector.mouseClick:connect(function()
    if clicked == false then 
        clicked = true
    else 
        return 
    end
end)

script.Parent.Touched:connect(function(hit)
    if clicked == true then
        if hit.Parent == nil then return end
        if hit then 
            if hit.Parent == Object1 then
                ---SCRIPT
            else
                if hit.Parent == Object2 then
                    ---SCRIPT
                end
            end
        end
    end
end)
0
Thank you so much! The script i'm currently using is: ROCKANDROLL572 12 — 6y
0
Better edit your post imo... arshad145 392 — 6y
0
Sorry about that. Just edited the post to show the script i'm currently using. ROCKANDROLL572 12 — 6y
Ad

Answer this question