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

i need help. ServerScriptService.CombatSystem:37: attempt to index nil with 'Stats' ?

Asked by 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
1
Answered by
pwx 1581 Moderation Voter
3 years ago

You can't call LocalPlayer on a server script.

Put

local Damage

inside the ServerEvent, and just use the automatic player parameter to obtain the damage, like so:

Combat.OnServerEvent:Connect(function(player,count)
    local Damage = 5 + player:WaitForChild('Stats').Level.Value
end)
0
thx man wyatt447 16 — 3y
Ad
Log in to vote
0
Answered by
Ghost40Z 118
3 years ago
Edited 3 years ago
local Level = game.Players.LocalPlayer:FindFirstChild("Stats").Level


local Damage = 5 + Level.Value

Try if this works, since sometimes it doesn't want to register the folders.

Edited

0
attempt to index nil with 'FindFirstChild' says that now wyatt447 16 — 3y
0
Try to make the level as a variable Ghost40Z 118 — 3y
0
I edited it Ghost40Z 118 — 3y
0
Nevermind. Another person sent something that should work. I thought you did this in a localscript. Ghost40Z 118 — 3y

Answer this question