#How do i make a counterattack function

1 messages · Page 1 of 1 (latest)

clear trench
#

like how do i make the targetplayer script check where if they hit a player that has a counter it does something i want to code in like how do i script that

#

heres the cilent/server

sinful pebble
#

like you hit someone 3x and it doubles damage as example? @clear trench

clear trench
#

like for debugging it prints "Sever:Player hits a countering player"

sinful pebble
#

if isCounter.Value then ... end?

sinful pebble
clear trench
#

i have like a hitbox that does the damage do you want to see it?

sinful pebble
#

nah i understand what you mean

#

does any of your scripts detect if a player is in that hitbox

clear trench
#

making the counter work

#

when on hit

sinful pebble
#

so your working on the onhit par

#

t

clear trench
#

yes

#

i got the damage now i need to make a counter just incase i use it for the future

sinful pebble
#

gimme a sek

clear trench
#

kk

#

oh yeah this is how im doing the script

sinful pebble
clear trench
honest trellisBOT
#

studio** You are now Level 4! **studio

sinful pebble
#

why is there a server script inside a local script

clear trench
#

so it can be organized

#

its inside a character

sinful pebble
#
local Players = game:GetService("Players")

local function getPlayersInHitbox(attackerCharacter, hitbox)
    local params = OverlapParams.new()
    params.FilterType = Enum.RaycastFilterType.Exclude
    params.FilterDescendantsInstances = {attackerCharacter}

    local parts = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size, params)
    local hitCharacters = {}
    local hitPlayers = {}

    for _, part in parts do
        local character = part:FindFirstAncestorWhichIsA("Model")
        
        if character and not hitCharacters[character] then
            local humanoid = character:FindFirstChildOfClass("Humanoid")
            if humanoid then
                hitCharacters[character] = true

                local player = Players:GetPlayerFromCharacter(character)
                if player then
                    table.insert(hitPlayers, player)
                end
            end
        end
    end

    return hitPlayers, hitCharacters
end

-- example usage for testing
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local hitbox = script.Parent
        local hitPlayers, hitCharacters = getPlayersInHitbox(char, hitbox)
        print(hitCharacters)
    end)
end)

this is what i came up with

sinful pebble
#

server scripts shouldnt be in the character

#

they should go in ServerScriptService

sinful pebble
#

we are excluding players / characters which already got hit

clear trench
#

so i should put it in serverscriptservice

sinful pebble
#

yea probably😭

#

also if that localscript is inside of a character it should also not work because the character is inside of workspace where localscripts dont run

#

or dont work

clear trench
#

OH NO

#

its in a uh

#

replicatedstorage

#

you morph into the character

sinful pebble
#

i would put it in startercharacterscripts tbh

clear trench
#

im like making a 1vall

sinful pebble
#

if it works for you leave it idkcrying

clear trench
#

but like i need a counter

#

hold on let meshow you the code when you get hit

#

its supposeto like break the loop if the character has counter

sinful pebble
#

thats not a loop...

clear trench
#

wym

sinful pebble
#

this will just run once

#

you can use smth like this

repeat
    --this will loop
until breakLoop
clear trench
#

kk

sinful pebble
#

So on what exactly do you need help now, i don't really understand how the counter is supposed to do

clear trench
#

uhm

#

im trying to make a boolvean true on server

#

so when a player uses a script that hits them

sinful pebble
#

do you mean parry with counter right

clear trench
#

somewhat

#

yes

sinful pebble
#

im gonna show you with my script is that okay?

#

with my hit detection script

#

how i would do it

clear trench
sinful pebble
#
local Players = game:GetService("Players")

local function getPlayersInHitbox(attackerCharacter, hitbox)
    local params = OverlapParams.new()
    params.FilterType = Enum.RaycastFilterType.Exclude
    params.FilterDescendantsInstances = {attackerCharacter}

    local parts = workspace:GetPartBoundsInBox(hitbox.CFrame, hitbox.Size, params)
    local hitCharacters = {}
    local hitPlayers = {}

    for _, part in ipairs(parts) do
        local character = part:FindFirstAncestorWhichIsA("Model")
        
        if character and not hitCharacters[character] then
            local humanoid = character:FindFirstChildOfClass("Humanoid")
            if humanoid then
                if character:GetAttribute("Parry") then -- give the character/player wtv you prefer an attribute, im gonna choose the character because im using a rig for testing and check if the Attribute (boolean) is set to true of false and then add them to the hitCharacters table or just skip to the next loop
                    continue
                end

                hitCharacters[character] = true

                local player = Players:GetPlayerFromCharacter(character)
                if player then
                    table.insert(hitPlayers, player)
                end
            end
        end
    end

    return hitPlayers, hitCharacters
end

-- example usage for testing
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local hitbox = script.Parent
        local hitPlayers, hitCharacters = getPlayersInHitbox(char, hitbox)
        print(hitCharacters)
    end)
end)
#

pretty easy

#

you just need in every players character / player instance an attribute which you can check

clear trench
#

OH wait thisdoes look easy

#

so why wasnt i thinking about this

#

brother

#

let me try this and ill give feedback if it works or im doing it wrong

sinful pebble
#

alr just ping me

#

normally you would use a state manager for this idk if you know what that is / how to use it though @clear trench
as example parry / attack / idle would be states which are just player attributes

#

there are libs for this

#

could be too complicated for you though

clear trench