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

Why won't my script work?

I am trying to make it so that when part1 touches part2, part2 unanchors. Here is the script:

function onTouched(hit)
if hit.Name=="Part2"
then
hit.Anchored=false
end
end
script.Parent.Touched:connect(onTouched)

5 comments

0

if anything, that would unanchor part1 instead of part2. You'd want to unanchor script.Parentinstead of hit.

0

Part1 IS script.Parent. Besides, I think I figured it out.

0

Still unsolved! I thought I found the problem but it is not so!

1

put then on line 2. Also is part2 "Part2" or "part2". Capitolization matters.

0

Why is nothing working?

3 answers

By your description.. " ... when part1 touches part2, part2 unanchors. " then it sounds like you don't want to be unanchoring what hit script.Parent, you wanna check that what hit it IS Part2 then unanchor script.Parent(Part1)

script.Parent.Touched:connect(function(hit)
	if hit.Name=="Part2" then
		script.Parent.Anchored = false
	end
end)

Okay, simple answer. Hit is something that is put into whatever hit it, so i believe hit.Parent.Name would work instead of hit.Name.

function onTouched(hit)
	if hit.Parent.Name=="Part2" then
		hit.Parent..Anchored=false
	end
end
script.Parent.Touched:connect(onTouched)
function onTouched(hit)
if hit.Name == "Part2" then--change "Part2" to exact name of part
hit.Anchored = false
else 
print("Not the part")
end
end

No problem

1 comment

0

You forgot to call the function bro.

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