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

When Block "A" touches block "B" anchor A, ELSE unachor A?

Asked by 3 years ago
Edited 3 years ago
01function onTouch(hit)
02 
03    local h = hit.Parent:FindFirstChild("A")
04    if hit.Parent:FindFirstChild("A") then
05        h.Anchored = true
06    else
07        h.Anchored = false
08    end
09 
10end

^ This is how far I was able to get

Hi All,

I'm trying to make a script where

it needs to constant check if: IF block "A" touches block "B" anchor block "A" ELSE if not touched by block "B" unanchor block "A" END

What would be the best to achieve the above?

note: block A and B is not in the same group

0
Hi dino thanks for your comment, as long as you can make the script locate block a and block b, it should work.. sne_123456 439 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

To achieve this, just use a script in workspace and use while loops,

You need 2 blocks in workspace one block that is called A and one that is called B

01local Ablock = game.workspace.A
02local Bblock = game.workspace.B
03while true do
04    local parttouchB = Bblock:GetTouchingParts() -- returns a table of parts intersecting B
05    for i,v in pairs(parttouchB) do
06        if v == Ablock then
07            Ablock.Anchored = true
08        else
09            Ablock.Anchored = false
10    wait()
11        end
12    end
13end

Hope this works.....

0
Line 07 & line 09 kinda sussy, I'll think it's "Anchored" instead of "Anchor". SpotTicker 15 — 3y
0
oh ye thanks sne_123456 439 — 3y
0
Thanks for the reply! The the script works perfectly, the only issue I have is that part A and B may not always be in workspace. It could be group into groups etc. Is there a way to make this happen? Dinoboshoff1 -17 — 3y
Ad

Answer this question