#how can i get the player in GetPartsInPart
11 messages · Page 1 of 1 (latest)
use a loop like a while loop or renderstepped or smth like that
so,
if Result then
-- check for player
end
end```
it is a loop
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
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)```
i fixed it using a for _, v in x do loop
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)```
but thanks for the help