I am making a banana tool for my game that will only trip players on opposite team. I am trying to clone a brickcolor value and set it to the players teamcolor. (This script is just inside tool)
local getPlayers = game:GetService("Players")
local player = getPlayers:GetPlayerFromCharacter(Tool)
local teamColor = Tool.teamColor:Clone()
print(player.TeamColor)
if teamColor.Value ~= player.TeamColor then
teamColor.Value = BrickColor.new(21)
end
The error I get from the print is:
Players.Its4Realzies.Backpack.BananaPeel.PlantBanana:21: attempt to index nil with âTeamColorâ
When you use the :Clone() function it stores a âCloneâ in the memory but you canât actually use it because itâs not parented to anything in the DataModel, once itâs parented to something you can use it.
There is not enough context here for me to tell what you are trying to do when you Clone it.
How about changing teamColor to teamColor = Tool.teamColor, because I assume thatâs already a BrickColorValue in the Tool.
Or explain to me why you are Cloning the BrickColorValue and what you plan on doing with it.
Yes I also think the :GetPlayerFromCharacter is the problem, because you put âToolâ as the parameter, :GetPlayerFromCharacter takes the player character and getâs you the player Instance.
If Tool is parented to the backpack, then the player will be Tool.Parent.Parent
Sorry for taking you on a tangent idk how I didnât notice this was the problem
I dont know what is happening is said it was in backpack and I did not change location of tool and I get this error message when I say player = script.parent.parent
TeamPlayer is not a valid member of Model âWorkspace.Its4Realziesâ
When the tool is equipped it will move from the backpack to the player character. Then when the tool unequips it moves back to the backpack. That is what is happening.