#how can i get the player in GetPartsInPart

11 messages · Page 1 of 1 (latest)

pearl plover
#

you must constanly fire the result

#

use a loop like a while loop or renderstepped or smth like that

#

so,

     if Result then
         -- check for player
     end
end```
spark harbor
#

inside a loop already

#

this is what im trying to do bro, check the player

    if Result then
        local Player = game.Players:GetPlayerFromCharacter(Result[#Result].Parent)
        print(Player)
    end
#

but idk how

pearl plover
# spark harbor this is what im trying to do bro, check the player ```lua if Result then ...

right, sorry for the long wait

here this should work:


local function getPlayer()
    for _, part in pairs(workspace:GetPartsInPart(Part, OverlapParams.new())) do
        if part then
            if part.Parent:FindFirstChildOfClass("Humanoid") then
                local character = part.Parent
                local player = game:GetService("Players"):GetPlayerFromCharacter(character)

                print(player.Name)
            end
        end
    end
end

Part.Touched:Connect(getPlayer)```
spark harbor
#

i fixed it using a for _, v in x do loop

pearl plover
#

this is probably better though:


local Part = script.Parent

RunService.Heartbeat:Connect(function()
    for _, part in pairs(workspace:GetPartsInPart(Part, OverlapParams.new())) do
        if part then
            if part.Parent:FindFirstChildOfClass("Humanoid") then
                local character = part.Parent
                local player = game:GetService("Players"):GetPlayerFromCharacter(character)

                print(player.Name)
            end
        end
    end
end)```
spark harbor
#

but thanks for the help