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

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

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

✓ Accepted answer

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)

3 comments

0

Thank you so much! The script i'm currently using is:

0

Better edit your post imo...

0

Sorry about that. Just edited the post to show the script i'm currently using.

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