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

Will this script work?

If I added this line to a script, would it work?

function Touched() -- Start
	if workspace.Part8 == false then -- the part that I am not sure about
		return -- is this right?
	end
end

-- There should be the connection line but don't worry about it.

If not how could it work?

This is for making sure that only one part is allowed to touch it.

1 answer

✓ Accepted answer

No.


workspace.Part8 would be a Part, an Instance. false is not an instance, so they cannot be equal.


The first (only) parameter to a Touched event is which part touched it. We can compare this parameter to workspace.Part8 to make sure it is workspace.Part8 triggering the Touch event:

function Touched(partTouching)
	if partTouching ~= workspace.Part8 then
		return;
	end
	-- Do stuff
end

I would say that in general it would probably be better to organize it like this instead, because it's easier to see at a glance what is going on:

function Touched(partTouching)
	if partTouching == workspace.Part8 then
		-- Do stuff
	end
end

But both versions work.


Instead of comparing workspace.Part8 and partTouching, you could just check the Name of partTouching:

if partTouching.Name == "Part8" then

This doesn't act the same, since there could be more than one Part8 but it may be sufficient. It's also useful if there are several parts which you want to accept and workspace.Part8 isn't the only one.

1 comment

0

Thank you! I named it Part8 so it would be unlike other parts, so it would be the only one of its kind. I suck at scripting, so thank you for helping me!

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