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?