So In my game, I made it so that every time my stand does an attack, it will check if the enemy humanoid, the one that the stand punched, has less than 1 health. Then if the enemy humanoid is dead, then It’ll add one to the player who killed the other one 1 kill on the leaderboard. Problem is, it shows in the output an error and does not change the kills by 1. This is what it shows in the output, ServerScriptService.Stand2Server.Barrage:102: attempt to index nil with ‘leaderstats’
Here is the code: ` if hit then
local EHumanoid = hit.Parent:FindFirstChild(“Humanoid”)
local EHumRP = hit.Parent:FindFirstChild(“HumanoidRootPart”)
if EHumanoid and EHumanoid.Health > 0 and not
EHumanoid:FindFirstChild("BarDeb") then
local BarDeb = Instance.new("BoolValue",EHumanoid)
BarDeb.Name = "BarDeb"
Debris:AddItem(BarDeb,.1)
EHumanoid:TakeDamage(Damage)
if EHumanoid.Health < 1 then
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
end
local sound = Instance.new("Sound",Folder)
sound.SoundId = "rbxassetid://2174934844"
sound.Volume = 1
sound:Play()
Debris:AddItem(sound,.5)
local wave = script:WaitForChild("Wave"):Clone()
wave.Parent = Folder
wave.CFrame = hit.CFrame
wave.Orientation = wave.Orientation + Vector3.new(90,0,0)
Debris:AddItem(wave,.25)
local goal = {}
goal.Size = wave.Size + Vector3.new(5,0,5)
goal.Transparency = wave.Transparency + (1 - wave.Transparency)
local info = TweenInfo.new(.25)
local tween = TweenService:Create(wave,info,goal)
tween:Play()
end
end`
Will someone help me figure out how to fix this?
Oh Sorry about that. Also no this is not in a local script. It still does not work. Now there’s an error on line 9. Same error in the output though as earlier.
local rp = game:GetService("ReplicatedStorage")
local Barrage = rp:WaitForChild("Stand2Remotes"):WaitForChild("BarrageHold")
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Damage = 15
local duration = 3
local debounce = false
function recall(Player, HumanoidRP, Stand, Folder)
Folder:Destroy()
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(2,0,2)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
local animControl = Stand:WaitForChild("AnimControl")
for i, track in pairs(animControl:GetPlayingAnimationTracks()) do
track:Stop()
end
local Idle = animControl:LoadAnimation(script:WaitForChild("Idle"))
Idle:Play()
end
Barrage.OnServerEvent:Connect(function(Player,active)
local Stand = workspace:FindFirstChild(Player.Name.." Stand"):FindFirstChild("Dummy")
if Stand and active == false then
debounce = true
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
Humanoid.WalkSpeed = 2
Humanoid.JumpPower = 0
local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
prevWeld:Destroy()
Stand:WaitForChild("HumanoidRootPart").CFrame = HumanoidRP.CFrame * CFrame.new(0,0,-2.5)
local weld = Instance.new("ManualWeld")
weld.Name = "Stand Weld"
weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
weld.Part1 = HumanoidRP
weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * HumanoidRP.CFrame
weld.Parent = weld.Part0
local animControl = Stand:WaitForChild("AnimControl")
for i, track in pairs(animControl:GetPlayingAnimationTracks()) do
track:Stop()
end
local Punching = animControl:LoadAnimation(script:WaitForChild("Punches"))
Punching:Play()
local Folder = Instance.new("Folder",workspace)
Folder.Name = Player.Name.." Barrage"
spawn(function()
wait(duration)
if debounce == true then
debounce = false
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
recall(Player, HumanoidRP, Stand, Folder)
Barrage:FireClient(Player)
end
end)
while wait() and debounce == true do
local ray = Ray.new(Stand:WaitForChild("HumanoidRootPart").CFrame.p + Vector3.new(math.random(-2,2),math.random(-1,1),math.random(-2,2)),Stand:WaitForChild("HumanoidRootPart").CFrame.lookVector * 2)
local hit, pos = workspace:FindPartOnRayWithIgnoreList(ray,{Character,Stand,Folder})
if hit then
local EHumanoid = hit.Parent:FindFirstChild("Humanoid")
local EHumRP = hit.Parent:FindFirstChild("HumanoidRootPart")
if EHumanoid and EHumanoid.Health > 0 and not EHumanoid:FindFirstChild("BarDeb") then
local BarDeb = Instance.new("BoolValue",EHumanoid)
BarDeb.Name = "BarDeb"
Debris:AddItem(BarDeb,.1)
EHumanoid:TakeDamage(Damage)
if EHumanoid.Health < 1 then
local plr = game.Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
plr.leaderstats.Kills.Value = plr.leaderstats.Kills.Value + 1
end
local sound = Instance.new("Sound",Folder)
sound.SoundId = "rbxassetid://2174934844"
sound.Volume = 1
sound:Play()
Debris:AddItem(sound,.5)
local wave = script:WaitForChild("Wave"):Clone()
wave.Parent = Folder
wave.CFrame = hit.CFrame
wave.Orientation = wave.Orientation + Vector3.new(90,0,0)
Debris:AddItem(wave,.25)
local goal = {}
goal.Size = wave.Size + Vector3.new(5,0,5)
goal.Transparency = wave.Transparency + (1 - wave.Transparency)
local info = TweenInfo.new(.25)
local tween = TweenService:Create(wave,info,goal)
tween:Play()
end
end
end
end
end)
Barrage.OnServerEvent:Connect(function(Player,active)
local Stand = workspace:FindFirstChild(Player.Name.." Stand"):WaitForChild("Dummy")
if Stand and active == true then
if workspace:FindFirstChild(Player.Name.." Barrage") and debounce == true then
debounce = false
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local HumanoidRP = Character:WaitForChild("HumanoidRootPart")
Humanoid.WalkSpeed = 16
Humanoid.JumpPower = 50
local Folder = workspace:FindFirstChild(Player.Name.." Barrage")
recall(Player, HumanoidRP, Stand, Folder)
Barrage:FireClient(Player)
end
end
end)
In this case, the error is on line 102.
Oof I mixed two folders up. It is in serverscript. The one in the players backpack holds local scripts. Don’t worry about that. The server script is connected to the local too.