Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why can't I detect any players in a Region3? [Solved By Me]

I'm trying to create a check to see how many players are still in a Region3, and increases the value of a variable if there is. The variable always reports 0, even if there are players in it. Parts are detected, I just don't need them.

local partsInRegion = game.Workspace:FindPartsInRegion3(region, Reg, 1000)
		local foundPlayers = 0
		for i, Reg in pairs(partsInRegion) do
			if Reg:FindFirstChild("Humanoid") ~= nil then
				print("Found "..Reg.Parent.Name)
				foundPlayers = foundPlayers + 1
			end
		end
		print(foundPlayers.. " players found.")
		if foundPlayers == 0 then
			Status.Value = "There are no more players remaining!"
		end

*Sorry for indentation, this is a really long script, and this is the important part.

All help is appreciated, LennyPlayzYT

2 comments

0

Why did you do Reg:FindFirstChild("Humanoid") if reg is a part? On line 4, reg seems to be the player. Then on line 5, it has a parent which the player.

0

So how do I fix the issue?

1 answer

Found the Issue, thanks to LoveSpeaksOutTruth.

Reg is equal to the character.

We can find the player by doing game.Players:GetPlayerFromCharacter(Reg.Parent), then get the player from there.

local partsInRegion = game.Workspace:FindPartsInRegion3(region, Reg, 1000)
        local foundPlayers = 0
        for i, Reg in pairs(partsInRegion) do
            if game.Players:GetPlayerFromCharacter(Reg.Parent) then
                print("Found "..Reg.Parent.Name)
                foundPlayers = foundPlayers + 1
            end
        end
        print(foundPlayers.. " players found.")
        if foundPlayers == 0 then
            Status.Value = "There are no more players remaining!"
        end

This discussion is preserved as it was. New answers, comments, and votes are closed.