I’ve made abilities; however, I was wondering how I can stop interrupting other abilities from hitting the player that being hit.
For example, if I M1 a player or cast an ability, how can I prevent another player M1 the player or cast an ability on the same player? I’ve tried attributes, however, if I check if an attribute is false such as stun or iframe, the ability wouldn’t work because it checks if the player stun is false or iframe is false.
I tried my best explaining, let me know if you need clarification.
Give the player iframes. Add a ForceField to their character while the ability is active, and make it invisible. For your damage/stunning methods, just check if the character has a forcefield instance inside it. If there’s a forcefield, do nothing
You could also use attributes to have a damage multiplier on the character which is read by all damaging scripts.
Let me clarify more, sorry if it was hard to understand.
I’ve already added a stun attribute and iframe attribute. The stun attribute is given when ability is casted to the player and remove their movement. The iframe attribute is given to the player who is casting the ability. The ability checks if the a player iframe attribute is false and blocking attribute is false. However, the problem is that if a third player casts an ability to a player that already being hit, I think they will be stun still. I tried made the script check for stun but if a player get stun when for example you slash, it won’t continue or follow up the attack.
you could use something like collison groups if the abilities are physical
“now i don’t have a deeper understanding of collision id”
i think you could do something like set two objects so that they don’t collide with each other…
something like that
or you could maintaina a variable like
player has been hit and
always check for it before the player gets damages
if playerHasbeenHit then
return
end
assign to true when the player was hit the first time
This is still quite confusing.
Let’s say there are three players: player1, player2 and player3.
You mean to say that if player1 is casting ability on player2, player3 shouldn’t be able to stun player2? But they can?
Let say it a beam ability. The beam checks if their iframe is false then it does damage. If I put iframe on player 2, it just wouldn’t do damage. Does that make sense? (This also applies for stun attribute)
Once a player is hit by the ability, you could put them inside a “whitelist” array and THEN give them iframes.
For every beam check, damage the player either if they have no iframes (if so, also add them to the array and give iframes), or if they are inside the array.
Imagine the function “check_hitbox()” returns all of the Humanoids inside the beam ability’s hitbox and function “has_iframes()” checks if a humanoid has iframes. “give_iframes()” will give a humanoid iframes.
local whitelist = {}
local function damage(humanoid, amount)
local in_whitelist = table.find(whitelist, humanoid) ~= nil
if has_iframes(humanoid) and not in_whitelist then return end
if not in_whitelist then
table.insert(whitelist, humanoid)
give_iframes(humanoid)
end
damage(humanoid, amount)
end
for i, humanoid in check_hitbox() do
damage(humanoid, 10)
end
obviously I used dummy functions so it may look slightly different in practice.
Btw, is there point creating the mentioned functions (like give_iframes()) if the beam already checks the hitbox and I can just change the attribute to true?
Ok I’ve made some changes that I think it could work, could you maybe review it?
This is the function.
local function InsertIFrame(character)
local in_whitelist = table.find(whitelist, character)
if character:GetAttribute("IFrame") and not in_whitelist then
return
end
if not in_whitelist then
table.insert(whitelist, character.Name)
character:SetAttribute("IFrame", true)
print(whitelist)
end
end
local function RemoveIFrame(character)
local in_whitelist = table.find(whitelist, character)
if in_whitelist then
for i,v in pairs(whitelist) do
if v == character.Name then
table.remove(whitelist, i)
end
end
character:SetAttribute("IFrame", false)
print(whitelist)
end
end
This how the function is called.
Humanoid:TakeDamage(Damage)
task.spawn(function()
local hasChanged = false
Humanoid.HealthChanged:Connect(function()
if hasChanged == false then
hasChanged = true
BeamHit:SetAttribute("Stunned", true)
InsertIFrame(BeamHit)
task.wait(4)
BeamHit:SetAttribute("Stunned", false)
RemoveIFrame(BeamHit)
end
end)
end)
In the first script, you need to make the insertiframe function return whether or not the character should be damaged, and I’ve also made the removing iframes a bit faster.
local function InsertIFrame(character)
local in_whitelist = table.find(whitelist, character)
if character:GetAttribute("IFrame") and not in_whitelist then
return false
end
if not in_whitelist then
table.insert(whitelist, character.Name)
character:SetAttribute("IFrame", true)
print(whitelist)
end
return true
end
local function RemoveIFrame(character)
local in_whitelist = table.find(whitelist, character)
if in_whitelist then
table.remove(whitelist, in_whitelist)
end
end
In the second script it looks like you’re just doing damage regardless of whether or not you SHOULD. This is rough, but the script for damaging a character should look something like this for you:
if InsertIFrame(character) then
Humanoid:TakeDamage(Damage)
end
Then, when the attack is over, you can loop through the whitelist and call RemoveIFrame for everyone inside.