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

How can I write the TeamColor of Parent:FindFirstChildOfClass("Humanoid")?

Asked by 5 years ago

I am modifying a slingshot script to prevent teamkilling. What I have been trying to do was that when a humanoid touches the projectile, it will not take damage if it has a certain teamcolor.

For reference, the humanoid = hit.Parent:FindFirstChildOfClass("Humanoid") and hit is when the humanoid comes in contact with the projectile.

Here is a snippet of what I have tried:

if humanoid.TeamColor("Deep Orange") then --don't take damage

Instead of Deep Orange, I also tried 1005 as it is the color code. Both have given me the same result with the projectile not causing damage to ALL humanoids, no matter if they are neutral or a different team.

My best guess is that instead of .TeamColor it is something else. I could not find any useful information in the Wiki of how to express TeamColor for a humanoid which is why I am asking here. Can anyone help me out?

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hey slikick,

Last I remember, Humanoid doesn't have a function or method or property called TeamColor. I think the team color is actually under the player. You can just get the player from the character and then check if the TeamColor's name is equal to whatever color you want not to be attacked. Something like this:

plrs = game:GetService("Players")

colors = { -- All the colors you don't want getting hurt.
    ["Deep orange"] = true
}

part = workspace.Part

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid") then
        local player = plrs:GetPlayerFromCharacter(hit.Parent)
        if not colors[player.TeamColor.Name] then -- Checks if the name exists in the table. I worked off the names of the BrickColor because everytime you call BrickColor.new, it creates a new BrickColor and can therefore not be compared since they cover different spaces in memory. 
            print("You dead bruh.")
        end
    end
end)

I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

KingLoneCat

Ad
Log in to vote
0
Answered by 5 years ago

TeamColor is a property of the player object. If you're using a local script, you can do something like:

local player = game.Players.LocalPlayer

if player.TeamColor ~= BrickColor.new("Deep orange") then --second word never capitalized
   player.Character.Humanoid:TakeDamage(20)
end

If it's a server script, you have to get the player some other way. Many events include it as a parameter, like PlayerAdded:

game.Players.PlayerAdded:Connect(function(player)
  local char = player.Character or player.CharacterAdded:Wait()
  local humanoid = char:WaitForChild("Humanoid")
  if player.TeamColor ~= BrickColor.new("Deep orange") then
    humanoid:TakeDamage(50)
  end
end)

You didn't really explain your scenario, so I can't help more than this. Nevertheless, I hope this helps!

0
he's preventing teamkilling not killing other players on other teams DeceptiveCaster 3761 — 5y
0
well he obviously needs to show more code then.. Gey4Jesus69 2705 — 5y

Answer this question