Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index nil with 'Stats'?

Asked by 3 years ago
Edited 3 years ago
local rp = game:GetService("ReplicatedStorage")
local Combat = rp:WaitForChild("Combat")

local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")

local Animations = script:WaitForChild("Animations")
local EnemyAnims = script:WaitForChild("EnemyAnims")
local Meshes = script:WaitForChild("Meshes")

local anims = 
{
        Animations:WaitForChild("Right"),
        Animations:WaitForChild("Left"),
        Animations:WaitForChild("Gut"),
        Animations:WaitForChild("Kick")
}

local eAnims =
{
        EnemyAnims:WaitForChild("EnemyRight"),
        EnemyAnims:WaitForChild("EnemyLeft"),
        EnemyAnims:WaitForChild("EnemyGut"),
        EnemyAnims:WaitForChild("EnemyKick"),
        EnemyAnims:WaitForChild("Break")
}

local limbs =
{
        "RightHand",
        "LeftHand",
        "RightHand",
        "RightFoot"
}

local Damage = 5 + game.Players.LocalPlayer.Stats.Level.Value
Combat.OnServerEvent:Connect(function(player,count)
    local Character = player.Character
    local Humanoid = Character:WaitForChild("Humanoid")
    local Humrp = Character:WaitForChild("HumanoidRootPart")

    local attack = Humanoid:LoadAnimation(anims[count])
    attack:Play()

    local Limb = Character:WaitForChild(limbs[count])

    local folder = Instance.new("Folder",Character)
    folder.Name = player.Name.." Melee"
    Debris:AddItem(folder,.5)

    local Hitbox = Meshes:WaitForChild("Hitbox"):Clone()
    Hitbox.CFrame = Limb.CFrame
    Hitbox.Parent = folder
    Debris:AddItem(Hitbox,.5)

    local weld = Instance.new("ManualWeld")
    weld.Part0 = Hitbox
    weld.Part1 = Limb
    weld.C0 = weld.Part0.CFrame:toObjectSpace(weld.Part1.CFrame)
    weld.Parent = weld.Part0

    Hitbox.Touched:Connect(function(Hit)
        if Hit:IsA("BasePart") then
            if not Hit:IsDescendantOf(Character) then
                local enemyHumanoid = Hit.Parent:FindFirstChild("Humanoid")
                local enemyHumrp = Hit.Parent:FindFirstChild("HumanoidRootPart")
                if enemyHumanoid and enemyHumrp then
                    local blockAction = enemyHumanoid:FindFirstChild("blockAction")
                    if blockAction then
                        --/Count towardds bracking
                        Hitbox:Destroy()

                        if blockAction.Value > 0 then
                            blockAction.Value = blockAction.Value - 1
                            if blockAction.Value == 0 then
                                local Break = enemyHumanoid:LoadAnimation(eAnims[5])
                                Break:Play()

                                blockAction:Destroy()
                                spawn(function()
                                    for i, anims in pairs(Humanoid:GetPlayingAnimationTracks()) do
                                        if anims.Name == "Block" then
                                            anims:Stop()
                                        end
                                    end


                                    local enemy = game:GetService("Players"):GetPlayerFromCharacter(enemyHumanoid.Parent)
                                    if enemy then
                                        local backpack = enemy:FindFirstChild("Backpack")
                                        if backpack then
                                            local CombatSystem = backpack:FindFirstChild("CombatSystem")
                                            if CombatSystem then
                                                local isBroken = CombatSystem:FindFirstChild("isBrocken")
                                                if isBroken then
                                                    isBroken.Value = true
                                                    --//Stun
                                                    wait(3)
                                                    isBroken.Value = false
                                                end
                                            end
                                        end
                                    end
                                end)    

                                local effects = Instance.new("Folder",workspace)
                                effects.Name = player.Name.." Effects"
                                Debris:AddItem(effects,.5)

                                local Wave = Meshes:WaitForChild("Wave")
                                Wave.CFrame = enemyHumrp.CFrame
                                Wave.Orientation = Wave.Orientation + Vector3.new(-90,0,0)
                                Wave.Parent = folder

                                local goal = {}
                                goal.Size = Wave.Size + Vector3.new(10,0,10)
                                local info = TweenInfo.new(.5)
                                local tween = TweenService:Create(Wave,info,goal)
                                tween:Play()

                            end
                        end

                    else
                        --/Do damage since they are not blocking
                        Hitbox:Destroy()

                        enemyHumanoid:TakeDamage(Damage)

                        local react = enemyHumanoid:LoadAnimation(eAnims[count])
                        react:Play()

                        if count == 4 then
                            local goal = {}
                            goal.CFrame = CFrame.new((Humrp.CFrame * CFrame.new(0,0,-15)).p, Humrp.CFrame.p)
                            local info = TweenInfo.new(.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
                            local tween = TweenService:Create(enemyHumrp,info,goal)
                            tween:Play()
                        end
                    end

                end 
            end
        end
    end)

    Combat:FireClient(player)
end)

line 36 has the problems. i want it to increase the damage by 1 every level up.

2 answers

Log in to vote
0
Answered by 3 years ago

It means that the value is equal to nil, which means in your Stats script, you need to put:

Example.Value = 0
0
doesnt work wyatt447 16 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This probably won't work but try

local Damage = 5
Damage = Damage + game.Players.LocalPlayer.Stats.Level.Value

if it didn't work before I edited it

0
still doesnt work wyatt447 16 — 3y

Answer this question