Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whitelisting a team in Anti-TK?

Asked by 6 years ago

Basically, I have a function that stops people from being able to team-kill. What I want to do, is add a certain team to a white list. Meaning, say you have a team named "Team1" on the Whitelist, anyone on Team1 will then be able to team-kill each other.

Code:

function Fire(ShootingHandle)
    local PierceAvailable = Module.Piercing
    PiercedHumanoid = {}
    if FireAnim then FireAnim:Play(nil,nil,Module.FireAnimationSpeed) end
    if not ShootingHandle.FireSound.Playing or not ShootingHandle.FireSound.Looped then ShootingHandle.FireSound:Play() end
    local Start = (Humanoid.Torso.CFrame * CFrame.new(0,1.5,0)).p--(Handle.CFrame * CFrame.new(Module.MuzzleOffset.X,Module.MuzzleOffset.Y,Module.MuzzleOffset.Z)).p
    local Spread = Module.Spread*(AimDown and 1-Module.SpreadRedution or 1)
    local Direction = (CFrame.new(Start,Mouse.Hit.p) * CFrame.Angles(math.rad(-Spread+(math.random()*(Spread*2))),math.rad(-Spread+(math.random()*(Spread*2))),0)).lookVector
    while PierceAvailable >= 0 do
        local Hit,EndPos = RayCast(Start,Direction,5000,Character)
        if not Module.ExplosiveEnabled then
            if Hit and Hit.Parent then
                local TargetHumanoid = Hit.Parent:FindFirstChild("Humanoid")
                local TargetTorso = Hit.Parent:FindFirstChild("Torso")
                local TargetTEAM = Hit.Parent:FindFirstChild("TEAM")
                if TargetHumanoid and TargetHumanoid.Health > 0 and TargetTorso then
                    if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then
                        InflictTarget:FireServer(TargetHumanoid,
                                                TargetTorso,
                                                (Hit.Name == "Head" and Module.HeadshotEnabled) and Module.BaseDamage * Module.HeadshotDamageMultiplier or Module.BaseDamage,
                                                Direction,
                                                Module.Knockback,
                                                Module.Lifesteal,
                                                Module.FlamingBullet)
                        PiercedHumanoid[TargetHumanoid] = true
                    end
                else
                    PierceAvailable = 0
                end
            end
1
Do use more local variables. User#19524 175 — 6y
1
If you're not going to help with my problem do not comment, thanks. GoddessHella 4 — 6y
1
I'm recommending you to use local variables, as global variables are bad practice. They make your code messy (as shown), pollute the global namespace and they can increase risks for name collisions. You should use local variables to prevent any possible future conflict User#19524 175 — 6y
1
Wow, snapping at someone who gave a good suggestion.... and this is where I don't look at this question anymore Shawnyg 4330 — 6y
View all comments (4 more)
1
He's pointing out something obvious, like I don't know. Basically just being a smart- by adding "thanks". His comment wasn't needed, and neither was yours. GoddessHella 4 — 6y
0
You could probably do something like create a table of whitelisted teams, like add an else statement to if TargetTEAM and TargetTEAM.Value ~= TEAM.Value where you check to see if their team is whitelisted Vulkarin 581 — 6y
0
" If you're not going to help with my problem do not comment, thanks." but he did help lol green271 635 — 6y
0
"with my problem" > You must have missed that.:) Again, another pointless comment. Thanks for the suggestion, Vulkarin. I'll take it into consideration. GoddessHella 4 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

For anyone wondering, I did end up fixing this myself. Basically I added a BoolValue to the teams that I wanted Whitelisted and set it to True for them and False for anyone else not on the whitelisted team. Then in the code I just added a check to the line:

if TargetTEAM and TargetTEAM.Value ~= TEAM.Value then

Like so:

if TargetTEAM and TargetTEAM.Value ~= TEAM.Value or TargetFFA.Value == true then

Thanks to anyone that tried helping me!

Ad

Answer this question