I was trying to make a item that can attack a player, but whenever I try to get character, it puts an infinite yield. I've been trying and trying, and it does not work.
I tried
local Character = player.Character or player.CharacterAdded:wait()
Doesn't work.
This is literally my whole script.
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:wait()
local Idle = player:WaitForChild("Character"):WaitForChild("Humanoid"):LoadANimation(script:WaitForChild("Idle"))
local Attack1 = player:WaitForChild("Character"):WaitForChild("Humanoid"):LoadANimation(script:WaitForChild("Attack1"))
local Attack2 = player:WaitForChild("Character"):WaitForChild("Humanoid"):LoadANimation(script:WaitForChild("Attack2"))
local num = 1
script.Parent.Equipped:Connect(function()
Idle:Play()
end)
script.Parent.Equipped:Connect(function()
Idle:Stop()
end)
script.Parent.Activated:Connect(function()
if num == 1 then
Attack1:Play()
script.Parent.RemoteEvent:FireServer()
else
Attack2:Play()
script.Parent.RemoteEvent:FireServer()
end
end)
Can anybody help me figure this out?

5 comments
On your Animations variables you do player:WaitForChild("Character") when you should only do Character
The Character Rig was already allocated, there is no need to yield for it once again. Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(AnimObject)
Isn't that what I said?
Where would I put Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(AnimObject) anyway?
Your attempt to reference the Character worked, that is the recommended practice to allocate it in a variable. It's the code below the statement that is failing.