Hello, so i have a combat system in a module script that you call From a Local Script, So i had no problem until I wanted to make NPCS. if you atleast have made a combat system before you know you have to set up Ticks and stuff.
So yeah as i stated before it was getting called from a local script and had no problem until i thought about making it For NPCS aswell. So i am thinking about carrying the system to the Server but i do not know How to Make Different Ticks For each Character thats going to use this. I’m sorry i couldn’t explain that well but i hope you understood
Create some kind of module which can store combat information for many characters
local CombatService = {}
-- Data
local combatInfo = {}
function CombatService.createCombatInfo(Character: Model)
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
combatInfo[Character] = {
lastTimeM1 = 0,
lastM1End = 0,
lastTimeM2 = 0,
lastTimeBlock = 0
}
-- event which automatically removes the combat info when this character dies (if that's what you wanted)
Humanoid.Died:Connect(function()
CombatService.removeCombatInfo(Character)
end)
end
-- do whatever else you want here
end
function CombatService.removeCombatInfo(Character: Model)
local characterCombatInfo = combatInfo[Character]
if characterCombatInfo then
combatInfo[Character] = nil
end
-- do whatever else you want here
end
-- an example of how you could also actually use the combat info
function CombatService.setCombatInfo(Character, infoName, newValue)
local characterCombatInfo = combatInfo[Character]
if characterCombatInfo then
local infoValue = characterCombatInfo[infoName]
if infoValue then
characterCombatInfo[infoName] = newValue
end
end
end
return CombatService
You can require a module like this anywhere on the server where you spawn characters, and call CombatService.createCombatInfo(Character) to create combat info for them, obviously you’ll need to tweak this to suit your needs, but I hope it gets the idea across to you.