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

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

function onTouch(hit)

	local h = hit.Parent:FindFirstChild("A")
	if hit.Parent:FindFirstChild("A") then
		h.Anchored = true
	else
		h.Anchored = false
	end

end


^ 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

1 comment

0

Hi dino thanks for your comment, as long as you can make the script locate block a and block b, it should work..

1 answer

✓ Accepted answer

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

local Ablock = game.workspace.A
local Bblock = game.workspace.B
while true do
	local parttouchB = Bblock:GetTouchingParts() -- returns a table of parts intersecting B
	for i,v in pairs(parttouchB) do
		if v == Ablock then
			Ablock.Anchored = true
		else
			Ablock.Anchored = false
	wait()
		end
	end
end

Hope this works.....

3 comments

0

Line 07 & line 09 kinda sussy, I'll think it's "Anchored" instead of "Anchor".

0

oh ye thanks

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.