Hey there, I’m working on a fighting game where the player chooses a class and fights in a 3D environment with special attacks relating to each class.
I was wondering how I could get a character to stop a function midway, If for example, Player1 hits Player2, And Player2 is attacking at the same time, But since Player2’s attack missed, They got stunned and the attack is canceled. How might I do that? It’s been a struggle trying to figure this out and I’ve been dumbfounded by the fact that I can’t fix it, So I’m resorting to making my own topic about this. Does anyone have a good idea? I’ve read similar posts relating to cancelling functions midway, But I’m completely unsure on how to go ahead with this. Does anyone have any ideas?
If the code is made of two different environments, get the server to read what status they were at while they are “verifying the attacks”. Once you have the check, ignore processing if the attack was missed.
Well you could have a stun variable for each player, and you could use an if statement in the middle of the function that checks the stun value. If it sees that the value is true then it returns the function, ending it.
And this is for some reason where I hit a brick wall; The function continues after the function returns, Which is confusing. Does it have to be a normal function or would it have to be apart of coroutine? I’ve got a set amount of animations to play, And it for some reason continues with doing the animations, Even though not only the function has been returned but another animation script has been fired to show the player getting hurt.
My last attempt checks every keyframe which is made for if the value is true. If it is, Return the function. So something like this:
if Hit.Value == true then
return
end
I honestly don’t know if I’m just dumb or I’m somehow messing it up in some sort of way.
Depends, what do you got so far, could we see your code for the function and what’s everything that you’re doing related to the function?
Alright. Let me send you an example.
local Hitted = false
local attack = false
function attackone() --new
attack = true
if Hitted == true then attack = false return end --this is what i've tried
--Animation keyframe 1 here
if Hitted == true then attack = false return end --once again, this is what i tried. it's a bit tedious though having to do it several times
--Animation keyframe 2 here
attack = false
end
This is an example of what I have. I have a different script to enable and disable a value in a configuration file which is Hitted’s value, Updated every time wait() is called.
Sorry for the very odd pronunciation of Hit. It’s called that there and ever since it’s kinda just been like that, And I’m too lazy to change the name by going through the entire script.
So from what I’ve found out, Hitted is being returned as nil even though it’s set to true… This is weird behavior and I’m unsure what to think of this. Is Roblox just broken relating to this?
If the attack missed, you’re likely only playing an animation that needs to be cancelled, correct? There’s no reason to run any code if no hit was detected, as far as I can really tell. Couldn’t you just stop any animations for the player that was hit and play any relevant hit stun animation and set any relevant variables? Like if I swing a sword and don’t hit anything, I’ve only really run a few lines of code that handle animation that can just be stopped from an outside function if I needed to. Maybe I’m completely off base with what you’re trying to do, or under thinking the solution though.
I’m not using Roblox Animations so that might not be possible. I’m using a much more… Obscure way. I’m using a mix of Lerp and Tween Animation using functions and the like, To replicate these animations on the server. I have tried this with an animation version and it seems to get the same issue, Even though it’s practically the same function, Removing specific lines to animate frame by frame and the such. Though, You have made me think of an idea in which relates to Keyframe names, And calling functions when the keyframe is met, Instead of doing stuff at specific times (waiting .5 seconds after playing the animation to create the hitbox, etc). I’ll give it a try and see if I can eradicate the problem using that. I’ll put your post as the solution as from what I can tell, It’s a much easier way of getting this to work.