Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Will this script work?

Asked by
cboyce1 40
9 years ago

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

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

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! cboyce1 40 — 9y
Ad

Answer this question