#Part that enables team kill

1 messages · Page 1 of 1 (latest)

nimble pilot
#

I need help making a part that makes it so that you can damage anyone even your own teamates but you can only kill teamates with a specific item in the users inventory. I tried using ChatGPT to help me but it didnt work.

trail quail
snow pond
#

stop asking for people to do it for you, make it urself and if it doesnt work then ask for help

snow pond
urban wolf
#

Make a pinged thingy

#

Wait one sec

#

Nvm

raw shell
snow pond
raw shell
raw shell
snow pond
raw shell
#

at least it sounds like he's already making his own game and has some progress into it, not just "Help me make this game"

nimble pilot
graceful nestBOT
#

studio** You are now Level 3! **studio

nimble pilot
#

ill send the code

#

local part = script.Parent

-- Store players who are touching the part
local playersInZone = {}

local function onTouch(other)
local player = game.Players:GetPlayerFromCharacter(other.Parent)
if player and not playersInZone[player] then
playersInZone[player] = true
end
end

local function onTouchEnded(other)
local player = game.Players:GetPlayerFromCharacter(other.Parent)
if player and playersInZone[player] then
playersInZone[player] = nil
end
end

part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

#

^ this is the script within the part that im using ^

#

local tool = script.Parent
local players = game:GetService("Players")

-- Reference to the special part
local zone = workspace:FindFirstChild("FriendlyFireZone")

local function isInZone(player)
if not zone then return false end
if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then return false end

local dist = (player.Character.HumanoidRootPart.Position - zone.Position).Magnitude
return dist < (zone.Size.Magnitude / 2)

end

local function onHit(hit)
local attacker = players:GetPlayerFromCharacter(tool.Parent)
if not attacker then return end

local victim = players:GetPlayerFromCharacter(hit.Parent)
if not victim then return end
if victim == attacker then return end -- Optional: skip self-damage

local inZone = isInZone(attacker)
local tool = script.Parent
local players = game:GetService("Players")
local workspace = game:GetService("Workspace")

if tool.Name ~= "Saber" then return end
-- Constants
local DamageValues = {
    BaseDamage = 5,
    SlashDamage = 10,
    LungeDamage = 30
}
local MaxReach = 8

-- Reference to the special part
local zone = workspace:FindFirstChild("FriendlyFireZone")

-- Detect if a player is in the zone
local function isInZone(player)
    if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then return false end
    if not zone then return false end

    local dist = (player.Character.HumanoidRootPart.Position - zone.Position).Magnitude
    return dist <= (zone.Size.Magnitude / 2)
end

-- Damage application logic
local function dealDamage(attacker, hit, damageAmount)
    local victim = players:GetPlayerFromCharacter(hit.Parent)
    if not victim or victim == attacker then return end

    local inZone = isInZone(attacker)

    if inZone or (attacker.Team ~= victim.Team) then
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid:TakeDamage(damageAmount)
        end
    end
end

-- Attack logic (assuming this is a sword)
local function performAttack(damageAmount)
    local character = tool.Parent
    local attacker = players:GetPlayerFromCharacter(character)
    if not attacker then return end

    local root = character:FindFirstChild("HumanoidRootPart")
    if not root then return end

    -- Use a ray to simulate weapon reach
    local rayOrigin = root.Position
    local rayDirection = root.CFrame.LookVector * MaxReach

    local ray = Ray.new(rayOrigin, rayDirection)
    local partHit, _ = workspace:FindPartOnRay(ray, character)

    if partHit then
        dealDamage(attacker, partHit, damageAmount)
    end
end

-- Slash and Lunge (customize to your tool's animations or triggers)
tool.Activated:Connect(function()
    -- Simple example using SlashDamage on left click
    performAttack(DamageValues.SlashDamage)
end)

tool.Activated:Connect(function()
local character = tool.Parent
local rayOrigin = character:FindFirstChild("Head").Position
local rayDirection = character:FindFirstChild("Head").CFrame.LookVector * 5

local ray = Ray.new(rayOrigin, rayDirection)
local part, pos = workspace:FindPartOnRay(ray, character)

if part then
    onHit(part)
end
end)

end

#

^ This is my script within the specific weapon^

#

@raw shell @snow pond

#

the reason why i didnt send it at first was bcuz i couldnt figure out how it worked and too me it looked like it was useless overall but is it better now?

nimble pilot
#

i tried making my own a while ago but it didnt work at all

raw shell
#

I see, I still need some more info about what's not working though, like what part are you supposed to have, what's that zone thing I saw in the script? basically explain to me like how you explained to chatGPT

raw shell
#

@nimble pilot Let me know so I can help u with your code

nimble pilot
#

tbh i dont know whats wrong with it but basically i made a .95 transparent non-collide part and the whole point of it is to let you kill your own teamates but u can only kill them with swords but make it so that you can still kill enemies if u use another weapon

raw shell
#

so really the only part that you'd need to change is the killing your teamamtes, I don't see any reason to touch the killings opponents code

graceful nestBOT
#

studio** You are now Level 6! **studio

raw shell
#

let me take a look at the code

raw shell
nimble pilot
raw shell
#

Okay so try adding a print in the isInZone function to check if it's actually in the zone just to make sure

local function isInZone(player)
if not zone then return false end
if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then return false end

local dist = (player.Character.HumanoidRootPart.Position - zone.Position).Magnitude
print(dist < (zone.Size.Magnitude / 2))
return dist < (zone.Size.Magnitude / 2)

end

#

And then at the end try this code:
tool.Activated:Connect(function()
local character = tool.Parent
local handle = tool:FindFirstChild("Handle") or character:FindFirstChild("HumanoidRootPart")
if not handle then return end

    local rayOrigin = handle.Position
    local rayDirection = handle.CFrame.LookVector * 5

    local rayParams = RaycastParams.new()
    rayParams.FilterDescendantsInstances = {character}
    rayParams.FilterType = Enum.RaycastFilterType.Exclude

    local result = workspace:Raycast(rayOrigin, rayDirection, rayParams)

    if result and result.Instance then
        onHit(result.Instance)
    end
end)
#

wait just realized u have 2 tool.Activated let me try to combine em

raw shell
# raw shell wait just realized u have 2 tool.Activated let me try to combine em

tool.Activated:Connect(function()
local character = tool.Parent
local attacker = players:GetPlayerFromCharacter(character)
if not attacker then return end

local handle = tool:FindFirstChild("Handle") or character:FindFirstChild("HumanoidRootPart")
if not handle then return end

local rayOrigin = handle.Position
local rayDirection = handle.CFrame.LookVector * 5

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {character}
rayParams.FilterType = Enum.RaycastFilterType.Exclude

local result = workspace:Raycast(rayOrigin, rayDirection, rayParams)

if result and result.Instance then
    local hit = result.Instance
    local victim = players:GetPlayerFromCharacter(hit.Parent)
    if victim and victim ~= attacker then
        local inZone = isInZone(attacker)

        if inZone or (attacker.Team ~= victim.Team) then
            local humanoid = hit.Parent:FindFirstChild("Humanoid")
            if humanoid then
                humanoid:TakeDamage(DamageValues.SlashDamage)
            end
        end
    end
end

end)