I attempted this myself but i’ve run out of ideas. I am not sure how to do it, i tried giving the part a humanoid, a number value with hp, i tried brick colour values to match team colour values, but i can’t figure out how to connect damage from things like roblox’s classic sword to the part, meaning i don’t know how to give damage to part’s health even though it has a team.
It all depends on how you handle dishing out damage to others which means you’ll probably have to look through all of your tools that can dish damage and check for other targetable instances you may have that is damagable such as armor and such.
local teamName = "yourteamnamehere"
script.Parent.Touched:Connect(funciton(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player.Team.Name ~= teamName then
-->> Kill player
end
end
end)
i don’t want to kill the player, i want to give a part lets say, 1000 hp, but i want the part to be on team red and only people on team blue to be able to deal damage to the part
A simple solution is that you can use a tag like a BrickColor tag and name it TEAM.
And then check if the attacker has a TEAM value and has the same value as the TEAM tag and it doesn’t (like in Salinas example above) target it.
You will have a part with a teamName string variable, or as @someonedie suggested, a tag.
You then modify your damage-dealing tools to check the tag or the variable.
Inside the weapon part you have to check to see if the humanoid (health) exist or if you’re using a special value like a armor value check for that if that exist. You can check by using FindFirstChild, as a example
local Damage = 25
local target = hit.Parent
local targetArmor = target:FindFirstChild("Armor")
local targetHumanoid = target:FindFirstChild("Humanoid")
if targetArmor then
targetArmor.Value = targetArmor.Value-Damage
elseif targetHumanoid then
targetHumanoid:TakeDamage(Damage) --Use TakeDamage for Humanoids
end
Oh that’s to see if there’s a instance called Armor inside of your armor model. It just checks if there is literally something called “Armor” (assuming it’s a integer value) inside the model and if it’s there, it takes away a few number.
Personally when I make vehicles or body armors in my game I insert a integer value and call it Armor and update my weapon scripts to make sure it target armor values and not just damage humanoids only. Personally it’s all up to you though.