I’m making a sword, it works but I’m trying to make it so you can’t kill players on the same team as you, I’ve searched up YT tutorials but got nothing.
This is what i’ve done
debounce = false
function onTouch(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if debounce == false then
if (humanoid ~= nil) then
humanoid.Health = humanoid.Health - 35
debounce = true
end
if debounce == true then
wait(2)
debounce = false
end
end
end
script.Parent.Touched:connect(onTouch)
function onTouch(part)
local hitplayer = game.Players:GetPlayerFromCharacter(part.Parent)
local hitter = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)--change this to get the player it is being used by.
if hitplayer.TeamColor ~= hitter.TeamColor then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if debounce == false then
if (humanoid ~= nil) then
humanoid.Health = humanoid.Health - 35
debounce = true
end
if debounce == true then
wait(2)
debounce = false
end
end
end
end
script.Parent.Touched:connect(onTouch)