Hey there! I’m going to be sharing some neat tricks I’ve learned (and how to implement them) over the near 6 years I’ve been on ROBLOX.
[center][size=4]How to harm based on team[/size]
I chose this for the first one because not everyone here scripts, and there’s a good chance clanners fall into that area. Having experience with clans, I was tasked with creating a sword that would only harm people on a different team.
While it can set a variable for this, you’d then have to make one sword per team. So instead, I made one that checked the attackers team against the attackees (?) team.
Please note I am modifying the standard LinkedSword script. [/center]
[spoiler][code]
function blow(hit)
if (hit.Parent == nil) then return end – happens when bullet hits sword
local humanoid = hit.Parent:findFirstChild(“Humanoid”)
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
local hum = vCharacter:findFirstChild(“Humanoid”) – non-nil if tool held by a character
if humanoid~=nil and humanoid ~= hum and hum ~= nil then
– final check, make sure sword is in-hand
local right_arm = vCharacter:FindFirstChild("Right Arm")
if (right_arm ~= nil) then
local joint = right_arm:FindFirstChild("RightGrip")
if (joint ~= nil and (joint.Part0 == sword or joint.Part1 == sword)) then
tagHumanoid(humanoid, vPlayer)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(humanoid)
end
end
end
end
[/code][/spoiler][center]
Now, to make this easier on me, I’m going to clean that up a bit…[/center]
[spoiler][code]
function blow(hit)
if not hit.Parent then return end
if type(hit.Parent) == ‘Model’ then – in case we hit a hat
local hHum = hit.Parent.Parent:FindFirstChild(‘Humanoid’)
else
local hHum = hit.Parent:FindFirstChild(‘Humanoid’)
end
local vC = Tool.Parent
local vP = game.Players:GetPlayerFromCharacter(vC)
local hP = game.Players:GetPlayerFromCharacter(hHum.Parent)
local vHum = vCharacter:findFirstChild(“Humanoid”)
if hHum and hHum ~= vHum and vHum then
tagHumanoid(humanoid, vP)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(hHum)
end
end
[/code][/spoiler]
[center]Now, we need to add a check comparing the two players teams!
It’s as simple as this:[/center]
if vP.TeamColor ~= hP.TeamColor then
[center]Final Code:
[spoiler][code]
function blow(hit)
if not hit.Parent then return end
if type(hit.Parent) == ‘Model’ then – in case we hit a hat
local hHum = hit.Parent.Parent:FindFirstChild(‘Humanoid’)
else
local hHum = hit.Parent:FindFirstChild(‘Humanoid’)
end
local vC = Tool.Parent
local vP = game.Players:GetPlayerFromCharacter(vC)
local hP = game.Players:GetPlayerFromCharacter(hHum.Parent)
local vHum = vCharacter:findFirstChild(“Humanoid”)
if hHum and hHum ~= vHum and vHum then
if vP.TeamColor ~= hP.TeamColor then
tagHumanoid(humanoid, vP)
humanoid:TakeDamage(damage)
wait(1)
untagHumanoid(hHum)
end
end
end
[/code][/spoiler][/center]