Hello. I'm trying to make a script that runs one thing if it's touching an object, and run another script if it isn't. Say A is the object I want to touch object B. I'm trying to make it so that when a button is clicked, if A is touching B, then run script 1. If A isn't touching B, run script 2. The current script i'm using is
script.Parent.ClickDetector.mouseClick:connect(function() if Workspace.Part.Touched:connect(function() then script.Parent.Parent.A.AlignOrientation.Enabled = true script.Parent.Parent.A.AlignPosition.Enabled = true wait(2) script.Parent.Parent.A.AlignOrientation.Enabled = false script.Parent.Parent.A.AlignPosition.Enabled = false end) else script.Parent.Parent.A.AlignOrientation.Enabled = false script.Parent.Parent.A.AlignPosition.Enabled = false wait(2) script.Parent.Parent.A.AlignOrientation.Enabled = true script.Parent.Parent.A.AlignPosition.Enabled = true end)
It doesn't do anything when clicked, so any help fixing this would be appreciated. Thanks!
Try making a touch function in the object and make it check whether the other one is touching if it is, it will run one script else, it will run the other.
EDIT:
ClickDetector Script:
script.Parent.ClickDetector.MouseButton1Click:Connect(function() --enable the script in object A or B end)
In Object A or B:
script.Parent.Touched:Connect(function(hit) if hit.Name == B then --enable said script here else --enable other said script end end)
You can do the same script in B, but change == B to == A. Also, disable these scripts, so that they only run once the button is clicked.