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

How can I make a part that gives an item only apply to a certain team?

Asked by 4 years ago

I am trying to make a click detector that only gives an item to a player if they are on a certain team. When I attempt to use it, it says that x is a nil value. Originally the script works fine as :

function hi(x)
        local y = x.Backpack
        local z = game.Lighting["Baseball"]
        z:Clone().Parent = y
end

script.Parent.ClickDetector.MouseClick:connect(hi)

However, when I use part of a team door script to try and make the part that gives the item a team only item, it breaks. The modified script that does not function is down below.

function hi(x)
    modelname="Baseball Player" -- Put the EXACT name of the team here
    if game.Players:playerFromCharacter(x.Parent).TeamColor==game.Teams:findFirstChild(modelname).TeamColor then
        local y = x.Backpack
        local z = game.Lighting["Baseball"]
        z:Clone().Parent = y
    end
end

script.Parent.ClickDetector.MouseClick:connect(hi)

Any idea how to make this function?

0
playerFromCharacter is deprecated. Try Players:GetPlayerFromCharacter, Also why are you using TeamColor instead of Team? User#30567 0 — 4y
0
For line 3 use this: if x game.Teams.[modelname]:FindFirstChild[x.Name] then -- Replace "Team name here" with your team name User#30567 0 — 4y

Answer this question