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

How can I get a Player from Region3?

Asked by 6 years ago
Edited 6 years ago

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

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  xxcoordinatorxx 135 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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
0
you could just use a remote to change teams Austinn_K 31 — 6y
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. xPolarium 1388 — 6y
0
ok, i'll give it a go! Bossons 4 — 6y
Ad

Answer this question