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

Is it possible to track if a player is standing on a part, and when it steps off?

Asked by 9 years ago

I am trying to make a platform that checks if multiple players are touching at the same time. What is the simplest way to do that? This is pretty much all I have l:

platform.Touched:connect(function(hit)
    local player  = hit.Parent
    if player.Character:FindFirstChild("RobberMatchTag") then
        local robber = player

    end
end)

1 answer

Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

All you would need to do, is something like this:

Touching={}

platform.Touched:connect(function(hit)
    local Valid=true
    local player = hit.Parent
    if player.Character:FindFirstChild("RobberMatchTag") then
        local robber = player
        for i=1, #Touching do
            if Touching[i]==robber then --Checks if players already touching
                Valid=false
            end
        end
        if Valid==true then
            Touching[#Touching+1]=robber
        end
    end
end)

platform.TouchEnded:connect(function(hit) --removes players from table when they stop touching
    local player = hit.Parent
    if player.Character:FindFirstChild("RobberMatchTag") then
        local robber = player
        for i=1, #Touching do
            if Touching[i]==robber then
            Touching[i]:remove()
        end
    end
end)

I think this should work. If you have any problems please leave a comment below. Hope I helped :P

1
Thank you for a really quick answer! :D SonioSony 53 — 9y
1
No prob, glad I could help :P dyler3 1510 — 9y
Ad

Answer this question