#Part that enables team kill
1 messages · Page 1 of 1 (latest)
stop asking for people to do it for you, make it urself and if it doesnt work then ask for help
its a help channel not a "we do it for you" channel
he never said he wants people to do it for them, just said help 😭
he didnt even share his code how r we meant to help without code?
Prob remove those who have that item from their team if they have the item? Or add a list of all those players that have the item on their inv
Def better if he sent the code, maybe he was jsut checking if someone actually had an idea on how to do it
maybe ive just seen too many grey roles begging for help for someone to do it all for them
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"
sorry this is my first time here
** You are now Level 3! **
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?
did u write this urself
i added the saber damage script myself but tbh everything else i got from chatgpt
i tried making my own a while ago but it didnt work at all
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
@nimble pilot Let me know so I can help u with your code
ok thx
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
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
** You are now Level 6! **
let me take a look at the code
So if you run the game what won't work is you killing your teamates and that's all?
yea they dont take damage within the part or "zone"
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
btw lmk what this prints
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)
