Log in to vote

How to make a part that damages a player in a specific team?

Asked by 11 months ago

How would I make a script in a part that damages a player on a certain team?

2 answers

Log in to vote
Answered by 11 months ago

Well, since the post doesn't say answered, and maybe you don't know how to adapt joshthegamer456's script, here it is

Just like joshthegamer456 said, just use player.Team

The script goes inside the part that will be touched

local DamagePerTouch = 25 -- How much damage per touch will it deal

local CooldownPerTouch = 0.5 -- How much time in seconds to be able to damage again

local TeamName = "Team Name Here" -- The exact name of the team

local part = script.Parent
local Team = game.Teams[TeamName]
active = true

function OnTouch(hit)
    local plr = hit.Parent
    if plr:FindFirstChild("Humanoid") then
        local user = game.Players:GetPlayerFromCharacter(plr)
        if user.Team == Team and active == true then
            active = false
            active = true

Log in to vote
Answered by 11 months ago

Ambiguity can be a killer!

Do you mean: A part that damages a player if the player is on a specific team


A part that damages a specific player on a specific team?

Futhermore, the lack of detail in your question makes it hard for me to answer your question with full code. Do you want it to be when it's clicked or when it's touched, does a specific player have to touch it? Detail is key.

No matter what your question is, it can be solved with the Player.Team property. I'll write some code of a brick that'll damage the player who clicks it if they're on a specific team as an example.

--put the click detector and the script in the part
clickDetector = script.Parent.ClickDetector
team = game.Teams["Insert Team Name Here"]
    if(plr.Team == team) then

Some stuff may be correct like incorrect event names or smth since I haven't used roblox in a hot moment, but adapt that code to what you need.

Sorry for not being too clear, I meant that when touched a player on a specific team, they will get damaged. Mystical_Un1verse 9 — 11mo

Answer this question