Okay so I’ll be using coroutines as they work like spawn(function() end), but with no delay and you can stop the script.
We’ll need to have a value for the coroutine so we can stop it from outside as well as a variable for the Hit Value.
local hitValue = -- Path to the hitValue
local gripCo -- This will be nill for now
Coroutines work like
spawn(function), but we wish to repeat the coroutine so we’ll have to give the function a name (as well as destroying the coroutine after it has ended).
Note, you probaly want to put this function under your variables and put parameters in. If they aren’t variables yet.
local function gripping (--[[char, humanoid, anim, anim2, enemychar]]) -- Naming the function so we can recall it multiple times.
if Gripping == true then
humanoid.WalkSpeed = 0
humanoid.JumpPower = 0
local NewBlood = Blood:Clone()
NewBlood.CFrame = char.HumanoidRootPart.CFrame * CFrame.new(0, 0, -1) * CFrame.Angles(0,0,0)
local BloodParticle = NewBlood:WaitForChild("Particle")
NewBlood.Parent = game.Workspace
enemychar.HumanoidRootPart.Anchored = true
for i, anims in pairs(enemychar.Humanoid:GetPlayingAnimationTracks()) do
if anims.Name == "Gripped" then
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
enemychar.Humanoid.Health = 0
enemychar.HumanoidRootPart.Anchored = false
char.HumanoidRootPart.Anchored = false
gripCo = nil -- So we can check if it's ended if we ever wish to.
After this we’ll have to create a coroutine as replacement for the
spawn(function) (on the exact line of the spawn function).
Every time we wish the player to start gripping someone we run this code:
coGrip = coroutine.create(gripping)
coroutine.resume(coGrip --[[,char, humanoid, anim, anim2, enemychar]]) -- Replace this with the parameters of the function.
Note, you’ve to start the coroutine as well. That’s why we use
Now we need to have a function to remove the coroutine every time you get hit.
gripCo = nil -- Stops the coroutine function (completely).
IMPORTANT, you’ll have to use another function to undo the changes (such as Anchoring the player and playing an Animation) with another function.