Team player of GetPlayerFromCharacter() not done right?

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’

What is tool in your script?

what is this Instance? and why are you cloning it?

You can have a BrickColorValue in the tool if you want then you can do

if BrickColorValue.Value ~= player.TeamColor then
     --stuff
end

tool in my script = script.parent

Its brickcolor value I am cloning so the banana knows the team its on

the clone is not parented to anything, try parenting it to something.

something? can you please specify on what you want
me to try?

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.

But the print line also had a error

This says "attempt to index nil with “TeamColor”, Player.TeamColor will be nil if you are not on a team, make sure you are on a team.

It works with other teams thing in the exact saem code so i think the getPlayerFromCharacter is the problem

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 :joy:

2 Likes

I tried what you said, but strange enough I’m getting the same error

I did only one parent and I got this:
TeamPlayer is not a valid member of Player “Players.Its4Realzies”

Tool is not a character so you cant use GetPlayerFromCharacter on it.

TeamPlayer? what’s TeamPlayer.

if the Tool is in Player.Backpack then you can just do

local Player = Tool.Parent.Parent

if teamColor ~= Player.TeamColor then
1 Like

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”

Is it somehow in both or something?

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.

I did not unequip the tool though any of the times