How To Stop Ability From Interrupting

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.

3 Likes

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.

2 Likes

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.

1 Like

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

1 Like

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?

1 Like

Yes I tried explaining that in depth. I’m not sure if they can or not but I’m pretty sure they can but I have no way to test it.

1 Like

You’ve tried giving both player1 and player2 iframes for the duration of the ability instead of just player1?

1 Like

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)

1 Like

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.

1 Like

What would that look like? Can you provide an example?

1 Like

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.

2 Likes

I’ll try that the next time I’m in studio!

1 Like

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?

1 Like

no you don’t need the functions, as long as the logic is the same it should work

2 Likes

How would I remove the IFrame?

1 Like

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)
1 Like

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.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.