Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Team gear script showing error, how would I go about fixing it?

Asked by 3 days ago

This script isn't mine and the person who made it didn't explain how it worked in their video. It was working for a couple of hours however, all of a sudden it is now coming up with an error. As a result of the error it is no longer working.

To explain what it is supposed to do, when you join each team you are given their specific gear (in my case key-cards). When you re-spawn you still have those key-cards.

This is the script

function teamFromColor(color)
for _,t in pairs(game:GetService("Teams"):GetChildren()) do
if t.TeamColor==color then return t end
end
return nil
end

function onSpawned(plr)
local tools = teamFromColor(plr.TeamColor):GetChildren()
for _,c in pairs(tools) do
c:Clone().Parent = plr.Backpack
end
end

function onChanged(prop,plr)
if prop=="Character" then
onSpawned(plr)
end
end

function onAdded(plr)
plr.Changed:connect(function(prop)
onChanged(prop,plr)
end)
end

game.Players.PlayerAdded:connect(onAdded)

and this is the error that it is coming up with 16:40:30.121 - TeamColor is not a valid member of Script The error takes me to line 6

2 answers

Log in to vote
0
Answered by 3 days ago

add a check in teamFromColor to make sure that t is a Team. t:IsA('Team')

0
I am new to scripting so I am not sure how I would do that. Do I just add t:IsA('Team')? If so would I put it in or before the function? jacksworld2808 0 — 3d
0
you would put it in the function, you can just put "t:IsA('Team')" in the if statement at line 3 (if t:IsA('Team') and t.TeamColor==color then return t end) kaytikookie 40 — 2d
Ad
Log in to vote
0
Answered by 3 days ago
Edited 3 days ago

Edit the teamFromColor function.

local function getTeamFromBrickColor(color)
    local TeamsService = game:GetService("Teams")
    local TeamsTable = Teams:GetChildren()
    for _, team in pairs(TeamsTable) do
        if team:IsA("Team") then -- if Instance is a team
            if team.BrickColor == color then
                return team -- return the team
            end
        end
    end
end

Answer this question