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

Making a specific group enter a door?

Asked by 8 years ago

Well I wanted team "ct" enter this door. Error says their is no property "Team" in Players. (Ex. Player.Team.TeamColor)

ctdoor = script.Parent

function open()
    ctdoor.CanCollide = false
    for transparency = 0, 1, .1 do
        ctdoor.Transparency = transparency
        wait(.1)
    end
end

function close()
    for transparency = 1, 0, -.1 do
        ctdoor.Transparency = transparency
        wait(.1)
    end
    ctdoor.CanCollide = true
end


function get_player(part)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if part:IsDescendantOf(player.Character) then
            return player
        end
    end
end

ctdoor.Touched:connect(function(part)
    local player = get_player(part)
    if not player then return end
    local allow = (
        player.Team.TeamColor == 'Really blue' --this doesn't works <<<
    )
    if allow then
        open()
        delay(4, close)
    end
end)

2 answers

Log in to vote
0
Answered by 8 years ago

Team is indeed, not a valid member or property of Player. But TeamColor is. You'd access it like so:

player.TeamColor

But you really should use the IsInGroup function.

group = 1

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFristChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent.Humanoid)
        if player:IsInGroup(group) then
            --do stuff
        end
    end
end)

Hope this helps. I'm tired, but I want to help all that I can; please forgive any of my incoherence.

0
I don't think "IsInGroup" helps it just does nothing. IsInGroup works for groups connected with roblox and not TeamColor hardhitsniper 30 — 8y
Ad
Log in to vote
0
Answered by
DevArk 50
8 years ago

I like how MINEBLOX106 thinks but here is a better way of doing it.

local group = 1

script.Parent.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') then
        if game.Players:FindFirstChild(hit.Parent.Name) then -- make sure its an actual player not a robot
            if game.Players[hit.Parent.Name]:IsInGroup(group) then
                open()
                wait(4)
                close()
            end
        end
    end
end)

Answer this question