I’m making a paintball game and I’m wondering how to make an anti-team kill script that actually works unlike all the YouTube tutorials and free models. Any help is appreciated!
Scroll down to the section named “Team Kill Check” for a good explanation. Here’s the code snippet from the section:
function checkTeamKill(playerAttack, playerVictim)
if playerAttack.Team ~= playerVictim.Team or playerAttack.Neutral or playerVictim.Neutral then
return false
end
return true
end
1 Like
Where would I insert this code? I’m using the fixed classic paintball gun by Pr0jectArledge, btw.
I combined the provided anti script with the paintball script.
Edit the “Paintball” script inside of the tool to this:
ball = script.Parent
damage = 16
function checkTeamKill(playerAttack, playerVictim)
if playerAttack.Team ~= playerVictim.Team or playerAttack.Neutral or playerVictim.Neutral then
return false
end
return true
end
function onTouched(hit)
local humanoid = hit.Parent:findFirstChild("Humanoid")
if hit:getMass() < 1.2 * 200 then
hit.BrickColor = ball.BrickColor
end
-- make a splat
for i=1,3 do
local s = Instance.new("Part")
s.Shape = 1 -- block
s.formFactor = 2 -- plate
s.Size = Vector3.new(1,.4,1)
s.BrickColor = ball.BrickColor
local v = Vector3.new(math.random(-1,1), math.random(0,1), math.random(-1,1))
s.Velocity = 15 * v
s.CFrame = CFrame.new(ball.Position + v, v)
ball.BrickCleanup:clone().Parent = s
s.BrickCleanup.Disabled = false
s.Parent = game.Workspace
--game.Debris:AddItem(s, 5)
end
if humanoid ~= nil then
local player = game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
local sameTeam = checkTeamKill(player,humanoid.Parent)
if not sameTeam then
tagHumanoid(humanoid)
humanoid:TakeDamage(damage)
wait(2)
untagHumanoid(humanoid)
end
end
connection:Disconnect()
ball.Parent = nil
end
function tagHumanoid(humanoid)
-- todo: make tag expire
local tag = ball:findFirstChild("creator")
if tag ~= nil then
local new_tag = tag:clone()
new_tag.Parent = humanoid
end
end
function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:findFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
connection = ball.Touched:connect(onTouched)
wait(8)
ball.Parent = nil
It should work. If not, use this edited model: Paintball Gun
Credits to @Limited_Unique for providing the anti script.
1 Like
Here’s the official classic paintball gun by Roblox.
1 Like