Workspace.Script:4: attempt to index nil with 'Character'
my script is for m1.
Error is on line 4
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://15516709205" -- replace with your animation ID
local LoadedAnimation = Humanoid:LoadAnimation(Animation)
local PunchCooldown = 1.9 -- cooldown time in seconds
local LastPunchTime = 0
local ComboCount = 0
local function Punch()
if tick() - LastPunchTime > PunchCooldown then
if ComboCount == 0 then
LoadedAnimation:Play("Punch1")
ComboCount = 1
elseif ComboCount == 1 then
LoadedAnimation:Play("Punch2")
ComboCount = 2
elseif ComboCount == 2 then
LoadedAnimation:Play("Punch3")
ComboCount = 0
end
LastPunchTime = tick()
end
end
local function onInputBegan(input, gameProcessedEvent)
if not gameProcessedEvent then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Punch()
end
end
end
game:GetService("UserInputService").InputBegan:Connect(onInputBegan)