hey guys,
I seem to be having a problem with yielding a coroutine.
local player = game:GetService("Players").LocalPlayer
repeat wait() until player.Character
local character = player.Character
local mouse = player:GetMouse()
local tool = script.Parent
local idleTrack = Instance.new("Animation")
idleTrack.AnimationId = "rbxassetid://7105595820"
local Animation = character:WaitForChild("Humanoid"):LoadAnimation(idleTrack)
local Enabled = true
local coRunning = true
local newThread = coroutine.create(function()
while coRunning do
wait()
character.Humanoid.Running:Connect(function(speed)
if speed > 5 then
Animation:Stop()
else
Animation:Play()
end
end)
end
end)
script.Parent.Equipped:Connect(function()
Animation:Play()
coRunning = true
coroutine.resume(newThread)
tool.Activated:Connect(function()
if Enabled == true then
script.RemoteEvent:FireServer("Combat", character.HumanoidRootPart.CFrame*CFrame.new(0,0,-2).p)
end
end)
end)
script.Parent.Unequipped:Connect(function()
coroutine.yield(newThread)
Animation:Stop()
coRunning = false
print("stopped")
end)
I thought Yield was used to “pause” a coroutine until called upon again?
Unequipped function never goes past the Yield line.
I get no errors.
Any ideas?