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

How can I get a Player from Region3?

So my aim is to make a zone-capture thing: I want to detect a player, get his/her team, then change the colour of the zone to the team colour.

I have this:

local regionPart = game.Workspace.BoundaryZone

local pos1, pos2 = (regionPart.position - (regionPart.Size/2)), (regionPart.position + (regionPart.Size/2))
local region = Region3.new(pos1, pos2)

while true do
	wait(1)
	local partsInRegion = workspace:FindPartsInRegion3(region, game.Workspace.Baseplate,1000)
	local playersFound = {}
	for i, v in pairs (partsInRegion) do
		if v.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player found in region!", v.Parent.Name)
			playersFound[v.Parent.Name] = v.Parent
			table.insert(playersFound, v.Parent)
			
		end
	end
	
		for i, vin pairs (playersFound) do
		spawn(function()
			--[[if v.TeamColor == game.Teams.Peace.TeamColor then
				wait(2)
				zone.BrickColor = v.TeamColor ]]--
			end
		end)
	end

end

The script I have detects the parts that make up the player's character, but as I said I want the overall player so I can change his/her team. I'm guessing I need to use "GetPlayerFromCharacter" but idk where to slip it in?

Many thanks for reading

1 comment

0

Yeah the GetPlayerFromCharacter will work well with the touched event i tell you to make np bc that's how you get their team 

1 answer

✓ Accepted answer

i use a localscript, i think it works with a normal script as long as you remove the "and v.Parent.Name ==localplayer.Name"

for i,v in pairs(workspace:FindPartsInRegion3(region,nil,100)) do
if v.Name == "HumanoidRootPart" and v.Parent.Name==localplayer.Name then
wait();
print(v.Parent.Name)
end
end

3 comments

0

you could just use a remote to change teams

0

This should be on a server script since you're working with Region3. Don't give the client the power to change what's in the region.

0

ok, i'll give it a go!

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