Team player of GetPlayerFromCharacter() not done right?

From what I see in the OP, you aren’t implementing any sanity checks if there is a valid player or not

To debug this even further, you should implement print statements:

local Tool = script.Parent

local getPlayers = game:GetService("Players")
local player = getPlayers:GetPlayerFromCharacter(Tool.Parent) or getPlayers:GetPlayerFromCharacter(Tool.Parent.Parent)
print(player)

if player then
    local teamColor = Tool.teamColor:Clone()
        print(player.TeamColor)
    if teamColor.Value ~= player.TeamColor  then
    	teamColor.Value = BrickColor.new(21)
        print("Not equal")
    else
        print("Equal")
    end
end
1 Like

That’s why, as I just said when the Tool is equipped it will move to the Player’s Character.

Try using getPlayers:GetPlayerFromCharacter(Tool:FindFirstAncestorOfClass('Model'))

Then add an if statement checking whether the player exists or not.

if player then
    if teamColor.Value ~= player.TeamColor  then
	    teamColor.Value = BrickColor.new(21)
    end
end

Also little FYI, what I find more reliable when using teams is using player.Team instead of player.TeamColor. You can also assign the team to an ObjectValue’s value if you’re relying on using values. This might just be me though.

18:45:13.798 Its4Realzies - Server - PlantBanana:22
18:45:13.798 Bright blue - Server - PlantBanana:27
18:45:13.798 Equal - Server - PlantBanana:32
18:45:13.799 Workspace.BananaPeel.SlipScript:21: Expected ‘then’ when parsing if statement, got ‘humanoid’

This is not the solution, but it helped me get solution so Ill mark it solution

Try creating a Team instead & do this?

local Teams = game:GetService("Teams")
local Tool = script.Parent

local getPlayers = game:GetService("Players")
local player = getPlayers:GetPlayerFromCharacter(Tool.Parent) or getPlayers:GetPlayerFromCharacter(Tool.Parent.Parent)
print(player)

if player then
    if player.Team ~= Teams.RandomTeam then
        local teamColor = Tool.teamColor:Clone()
    	teamColor.Value = BrickColor.new(21)
        print("Not equal")
    else
        print("Equal")
    end
end
1 Like