Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

thx man

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

4 comments

0

attempt to index nil with 'FindFirstChild' says that now

0

Try to make the level as a variable

0

I edited it

0

Nevermind. Another person sent something that should work. I thought you did this in a localscript.

This discussion is preserved as it was. New answers, comments, and votes are closed.