How do I make a stun that updates?

I wanted to make my own stun handler for my game, without using the popular module. Anyways, I know how to set the stun, but I don’t know how to make the status update upon being hit again.

I just need someone to give me a rundown on how to do this. I’m thinking of making a runservice connection and using os.clock() but I’m not sure how to implement this.

Here’s what I’ve made thus far:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local AnimationFolder = ReplicatedStorage.Assets.Animations.StunAnimations

local StunTable = {}

local StunHandler = {}

local Stunanimations = {

function StunHandler:RidStun(char)
	local Stunned = char:GetAttribute("Stunned")
	if Stunned then 
		StunTable[char] = false
		char:SetAttribute("Stunned", false)

function StunHandler:Trigger(char, stuntime)
	local Stunned = char:GetAttribute("Stunned")
	local hum = char:WaitForChild("Humanoid")
	if not Stunned and StunTable[char] == nil then
		char:SetAttribute("Stunned", true)
		StunTable[char] = stuntime
		StunTable[char] = nil
		char:SetAttribute("Stunned", false)

return StunHandler
1 Like

Took a week but I found out how to do it here is some of the sauce (It’s kinda similar the StunHandlerV2 module, but if you want to make your own checks and whatnot it’s easier to do it from scratch.):

  1. Check if player is stunned, if not then store them in a dictionary Stunned[character]
Stunned[character] = {
Startime = os.clock(),
Duration = duration
  1. Make the values for the dictionary (Starttime and Duration)
  2. Make a variable for a runservice connection, if the connection == nil then set a runservice connection to that variable connection = Runservice...
local connection
if connection == nil then
   connection = Runservice.Heartbeat:Connect... 
  1. Loop through the table and check if the time is up, then attribute to false. Also, remove the character or humanoid from the table by setting it to nil. Add a statement to check if there are anymore characters or humanoids left in the table. If there are, disconnect the connection and set it to nil

If the player was already stunned and you need to reset it. Reset the StartTime and Duration.

-- the first check for the character or humanoid and the rest of the stuff
Stunned[character].Duration = duration
Stunned[character].StartTime = os.clock()

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