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

Why is it still removing the bike inside the part?

Asked by
Filipalla 504 Moderation Voter
5 years ago
local playerfound = false

function CreateRegion3FromPart(Part)
    return Region3.new(Part.Position-(Part.Size/2), Part.Position+(Part.Size/2))
end

function PlayersCanBikePart(part)
    local region = CreateRegion3FromPart(part)
    local partsInRegion = workspace:FindPartsInRegion3(region,nil,math.huge)
    local Players = {}


    for i,Part in pairs(partsInRegion) do
        local player = game.Players:GetPlayerFromCharacter(part.Parent)
        if player then
            for i,v in pairs(Players) do
                if Players[i].Name == player.Name then
                    playerfound = true
                end
            end

            if playerfound == false then
                table.insert(Players, player)
            end
            playerfound = false
        end
    end

    local whitelist = {}
    local SupportLib = require(script.SupportLibrary)
    for i,v in pairs(game.Players:GetPlayers()) do
        if not SupportLib.IsInTable(Players,v) then
            --Check if player has bike
            if not SupportLib.IsInTable(whitelist,v.Name) then
                local bike = v.Backpack:FindFirstChild("Bike")
                local bike2 = v.Character:FindFirstChild("Bike")
                if bike then
                    if bike:IsA("Tool") then
                        bike:Destroy()
                    end
                elseif bike2 then
                    if bike2:IsA("Tool") then
                        v.Character:FindFirstChildOfClass("Humanoid"):UnequipTools()
                        bike2:Destroy()
                    end
                end
            end

            return
        end
    end
    end
--V For Debugging V--
wait(20) --time to get inside part
print("Wait is now over")
--^ For Debugging ^--
while wait(.5) do
    PlayersCanBikePart(workspace.BikeArea)
end

Im trying to remove bikes from players who aren't in a specified area but even when im in that area the bike still gets removed and i can't figure out what i have done wrong.

Answer this question