#How do i make a counterattack function
1 messages · Page 1 of 1 (latest)
like you hit someone 3x and it doubles damage as example? @clear trench
no like a character doesaability and if that characterwhile the other counter is true a thing happens
like for debugging it prints "Sever:Player hits a countering player"
if isCounter.Value then ... end?
so how you could achieve ts?
i have like a hitbox that does the damage do you want to see it?
nah i understand what you mean
does any of your scripts detect if a player is in that hitbox
no thats where im currentlyy stuck at
making the counter work
when on hit
yes
i got the damage now i need to make a counter just incase i use it for the future
gimme a sek
whats this
its like how imdoing the counter
** You are now Level 4! **
why is there a server script inside a local script
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
ts doesnt make any sense to me
server scripts shouldnt be in the character
they should go in ServerScriptService
this way you know what characters (rigs) & what players got hit
we are excluding players / characters which already got hit
so i should put it in serverscriptservice
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
i would put it in startercharacterscripts tbh
im like making a 1vall
if it works for you leave it idk
does this help you
oh hey this is alright
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
thats not a loop...
wym
this will just run once
you can use smth like this
repeat
--this will loop
until breakLoop
kk
So on what exactly do you need help now, i don't really understand how the counter is supposed to do
uhm
im trying to make a boolvean true on server
so when a player uses a script that hits them
do you mean parry with counter right
im gonna show you with my script is that okay?
with my hit detection script
how i would do it
with this one
kk
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
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
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
idont know how to use a state manager