Trying to perfect my stun system

This might be my fifth post on my system, but i need some help.
Well, basically i need to not unstun them while the opponent is combo-ing them, so basically what happens is that i wait a second and then i unstun them, but when the 1 second is over they can get out of the combo, now how would i go on about making a kind of system that kinda “adds” onto the stun time every time they get punched.

4 Likes

Maybe set a timer for how long it will be until the person loses the “stunned” debuff. For example, a single punch would set the timer until the “stunned” debuff to os.clock()+1, then another punch is added and the value just gets a +=1. Under this system though, you’d have to check any input that comes in ensure the person is not stunned.

2 Likes

While “unstuning” them, add a check for some sort of value. Have something else control this value.

E.g.,

local StunTime = 0

local function Unstun()
if StunTime <= 0 then
-- unstun them
else
StunTime = StunTime - 1
end
end

local function Punch()
StunTime = StunTime + 1
end

that doesnt seem like a timer tho, since when they get punched they get stunned, and when it waits the StunTime it wont be updated by it changing, right.

How does os.clock() work? And could i detect when the clock ended? if so that would be fantastic.

os.clock() works like a more precise tick(). However, there is no way to signal that the clock has ended. This means you would have to check every input to see if the player is stunned or not. This is highly inefficient, but the only way to do it safely.
If you wanted to make an efficient system, you could do it on the client side, but that would open up the avenue for exploiters to simple disable that system.

Lots of games struggle with a stun system. Jailbreak, Combat Warriors, Dungeon Quest, and a slew of other games all opted for an efficient (yet insecure), client-sided stunning system.

1 Like

Just a question, how do you check the time? And, could i just do task.spawn() and make a function that checks it like, super fast

You could save the time to a NumberValue, and then compare the current time to the time that the stun is supposed to be over, then allow/deny the move based on the comparison.

Okay, found out that os.clock() is pretty confusing, maybe i can make a function that checks if the player was hit in the duration of the stun, and then if they were hit i do another wait(StunTime)

since you’re talking about stun time and stun immunity feature, let’s say its something very similar to hexaria, when you stun an opponent with a move for like a turn and after that turn is over, they receive a temporary 3-move anti-stun immunity which literally prevents them from being stunned again

in this case, you can try creating a function that fires when you hit an opponent and check if they don’t have a stun immunity (you can make this instance by creating a folder or a bool value whatever name it “immuneStun” and if it’s not activated then you can do your way of stunning people

you can use “delay(function(waitTime)” which is like “spawn(function()” but with a timer that allows other threads to proceed in free will, you can write 1 as the waitTime and you write inside the function to create that immuneStun thing which lasts for 5 seconds (try using debris) i guess

I think i found a better way to do this, i make a while loop that that checks if the timer is endtime, and the timer increases by 0.1 every millisecond. and then, every time they get punched, if the endtime hasnt reached its goal it gets increased by 1, im bad at explaining but i think this makes sense.

well actually a millisecond is a thousandth of a second (1/1000)

so in one second, it basically hits 100

ah man, its way too long since 2nd grade, im starting to forget. haha, anyways i meant a 1/10 of a second lol

i also thought millisecond was 1/100th of a second, also is the problem fixed? will the while loop trigger as soon the opponent gets combo’d and give the stun immunity after it checks that its endtime?

also what hierarchy is your script placed at

yeah, i use task.spawn to spawn in a new loop and set the stun to true, when the endtime reaches its goal it puts stun to false and yeah, gets done
Edit: i havent tested it, forgot to mention, thats just the logic of the script.

Update: It works perfectly, i’ve tested it with my combat and im really impressed by the results, here is the script:


					
					task.spawn(function()
						if isStarted == false then
							isStarted = true
							print("Started!")
							print(endtime)
							local isStunned = true
							humanoid.WalkSpeed = 0
							humanoid.JumpPower = 0
							humanoid.Parent.Fists.Enabled = false
							while isStunned == true do
								timer += 0.1
								if timer >= endtime then
									endtime = 0
									timer = 0
									isStunned = false
									isStarted = false
									print("Ended.")
									humanoid.WalkSpeed = 16
									humanoid.JumpPower = 50
									humanoid.Parent.Fists.Enabled = true
								end
								print(timer)
								wait(0.1)
							end
						end
					end)

dont mind the indents its cause the script i put it inside is long

Be careful; exploiters can manipulate their humanoid.WalkSpeed and humanoid.JumpPower despite what a server might change it to.

1 Like

yup i know its kinda just a placeholder for my future replacement

1 Like

Hey, would you reccomend adding a bodyvelocity with gravity that prevents them to go all ways but down?

The players have ownership on the physics of their character. No amount of BodyMovers will give you full control over how they move. You could set the physics ownership to the server, but the performance will be very botched.