Each skill in my game is a different module script stored in replicated storage that each player can require(). But if the player using the skill is hit I want them to stop using the move. How would I stop the module script from playing?
wrap it in a task.spawn()
and then use task.cancel(thead)
where the argument in the cancel is what’s returned from task.spawn
Wrap the function call or inside the module script?
Well how is your ability module setup?
Along the lines of
Module:
Ability.Start()
—do some stuff
—animation start
Particles:Emit(10)
End
Client replicator
Remote.OnClientEvent:Connect(function(module, args)
module.Start(args)
end)
With a server script getting all the inputs and sending out to the script above which modules clients should use
2 Likes
Something like below vvv
local abilityTaskHolder = {}
--start it here
Remote.OnServerEvent:Connect(function(player, module, args)
abilityTaskHolder[player] = task.spawn(module.Start, args)
end)
--how to cancel thread
task.cancel(abilityTaskHolder[player])
As an example for how tasks work, I wrote a demo code you can copy paste into the console below to see it in action:
--creates a while loop that cancels when `count` is 10
local taskExample = task.spawn(function()
local count = 0
while count < 10 do
count+=1
print(count)
task.wait(1)
end
end)
--waits 3 seconds
task.wait(3)
--stops the task from continuing
task.cancel(taskExample)
print("task cancelled")
1 Like
Thank you! This is very helpful
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.