This question is probably extremely specific but I need to handle value changes in a way that doesn’t break other moves. Earlier this or last week, I made a forum post stating a problem I am having with my combat. I tried making a thread handler but it just doesn’t work as intended.
As shown in this video below, my friend gets hit by multiple attacks yet his movement and attribute value get reset back to normal due to a delay I put in the server code.
task.delay(1, function()
print("CHANGING ISATTACKED")
Player2:SetAttribute("IsAttacked", false)
Player2.Humanoid.WalkSpeed = 16
Player2.Humanoid.JumpHeight = 7.2
end)
This is the thread handler I made but the cancelation of threads doesn’t work.
local ThreadModule = {}
local Threads: {[string]: "function" | () -> ()} = {}
function ThreadModule.RegisterThread(ThreadName: string, Thread, ...)
assert(type(ThreadName) == "string", "Argument 1 needs to be a string, got "..typeof(ThreadName))
assert(type(Thread) == "function", "Argument 2 needs to be a function, got "..typeof(Thread))
if Threads[ThreadName] ~= nil then
ThreadModule.MutilateThread(ThreadName)
else
Threads[ThreadName] = coroutine.create(Thread, ...)
end
end
function ThreadModule.CallThread(ThreadName: string)
local FoundThread = Threads[ThreadName]
if FoundThread then
local status = coroutine.status(FoundThread)
if status == "suspended" or status == "normal" then
local success, error_message = coroutine.resume(FoundThread)
if not success then
warn("Error in thread: " .. error_message)
ThreadModule.MutilateThread(ThreadName)
end
else
ThreadModule.MutilateThread(ThreadName)
end
end
end
function ThreadModule.MutilateThread(ThreadName: string)
local FoundThread = Threads[ThreadName]
if FoundThread then
coroutine.close(FoundThread) do
Threads[ThreadName] = nil
--coroutine.yield()
end
end
end
function ThreadModule.CheckThreadHealth(ThreadName: string): string
local FoundThread = Threads[ThreadName]
if FoundThread then
return coroutine.status(FoundThread)
end
end
return ThreadModule
If there is an alternative way of fixing my issues please lmk!