Delay in throwing grenade

I was making a throwable grenade, it works but theres a delay from the time the animation ends to when the grenade is thrown, i want it to be thrown in the middle of the animation but i dont know how i could do it.

–Script

local tool = script.Parent
local debris = game:GetService("Debris")

tool.Activated:Connect(function ()
	local player = game.Players:GetPlayerFromCharacter(tool.Parent)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local animator = humanoid:FindFirstChild("Animator")
	local root = character:FindFirstChild("HumanoidRootPart")
	local anim = game.ReplicatedStorage.Animations.Throw
	local AnimTrack = animator:LoadAnimation(anim)
	AnimTrack:Play()
	AnimTrack:AdjustSpeed(2)
	AnimTrack.Ended:Wait()
	local grenade = tool.Model:Clone()
	grenade.Parent = workspace
	grenade.Hand.CFrame = tool.Model.Hand.CFrame
	grenade.Hand.CanCollide = true
	grenade.ok.CanCollide = true
	grenade.Part.CanCollide = true
	grenade.Hand.Velocity = (root.CFrame.LookVector + Vector3.new(0,1.5,0)) * 50
	tool:Destroy()
	local Explosion = game.ReplicatedStorage.Explosion:Clone()
	task.wait(3.45)
	Explosion.Parent = workspace
	Explosion.Position = grenade.ok.Position
	grenade:Destroy()
	task.wait(0.1)
	Explosion.ParticleEmitter.Enabled=false
	debris:AddItem(Explosion,1)
end)

You could utilize AnimationEvents

1 Like

you could add animation markers and use AnimTrack:GetMarkerReachedSignal or you could also do this:

local tool = script.Parent
local debris = game:GetService("Debris")

tool.Activated:Connect(function ()
	local player = game.Players:GetPlayerFromCharacter(tool.Parent)
	local character = player.Character
	local humanoid = character:FindFirstChild("Humanoid")
	local animator = humanoid:FindFirstChild("Animator")
	local root = character:FindFirstChild("HumanoidRootPart")
	local anim = game.ReplicatedStorage.Animations.Throw
	local AnimTrack = animator:LoadAnimation(anim)
	AnimTrack:Play()
	AnimTrack:AdjustSpeed(2)
	
	repeat task.wait() until (AnimTrack.TimePosition > (AnimTrack.Length/2))
	
	local grenade = tool.Model:Clone()
	grenade.Parent = workspace
	grenade.Hand.CFrame = tool.Model.Hand.CFrame
	grenade.Hand.CanCollide = true
	grenade.ok.CanCollide = true
	grenade.Part.CanCollide = true
	grenade.Hand.Velocity = (root.CFrame.LookVector + Vector3.new(0,1.5,0)) * 50
	tool:Destroy()
	local Explosion = game.ReplicatedStorage.Explosion:Clone()
	task.wait(3.45)
	Explosion.Parent = workspace
	Explosion.Position = grenade.ok.Position
	grenade:Destroy()
	task.wait(0.1)
	Explosion.ParticleEmitter.Enabled=false
	debris:AddItem(Explosion,1)
end)

wish i knew about this before!

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