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

Is there such thing as a "IsStill" function?

Asked by 8 years ago

Is there such thing as a "IsStill" function that can be used for stuff like touched to see after a specific period of time if the function is still being triggered. For example a user could have touched a part. Then after 5 seconds you see if the user is still touching the part. If no such function exists how can I do this manually.

0
Use Touched and TouchEnded RubenKan 3615 — 8y

1 answer

Log in to vote
1
Answered by
luadotorg 194
8 years ago

Hello.

No, there is no thing such as a "IsStill" function. However, you can create your own. To do this, you will use the Touched event.

Here is some code:

script.Parent.Touched:connect(function(part)

end)

script.Parent.TouchEnded:connect(function(part)

end)

Now you must store the parts so that on TouchEnded you can decide which is the part and which isn't.

Now let's make a table, and a function.

Parts = {}

function IsStill(Part)
    return false
end

script.Parent.Touched:connect(function(part)

end)

script.Parent.TouchEnded:connect(function(part)

end)

Since we made the table, we will store that part on the table, then verify if it isn't there anymore. This way, you can check if the existent part is on the Parts table.

Parts = {}

function IsStill(Part)
    for i=1,#Parts do
        if (Parts[i] == Part) then
            return true
        end
    end

    return false
end

script.Parent.Touched:connect(function(part)
    table.insert(Parts, part)
end)

script.Parent.TouchEnded:connect(function(part)
    for i=1,#Parts do
        if Parts[i]==part then
            table.remove(Parts, i)
        end
    end
end)

Hope this helps you out! ~luadotorg

0
Nice! There is also is IsTouching function, I believe. OldPalHappy 1477 — 8y
1
Hi, thanks for commenting. I cannot find "IsTouching" anywhere. I did find "GetTouchingParts" however, and that completely gone missing from me. It seems to work best with anchored parts. luadotorg 194 — 8y
0
Questions are answered a lot quicker thanks shabbs15 67 — 8y
Ad

Answer this question