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?
Hey slikick,
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)
Thanks,
Best regards,
KingLoneCat
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!