Issue with finding folder

Hello! I’m attempting to make an attack, although when I try to find the person who was hit’s folder (its a folder with all their information related to combat like stuns and their percent value) it returns nil. Here is the code:

local Event = game.ReplicatedStorage.CombatEvents.Jab
game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(c)
		local Conditions = Instance.new("Folder", c)
		Conditions.Name = "Conditions"
		local IsStunned = Instance.new("BoolValue", Conditions)
		IsStunned.Name = "IsStunned"
		IsStunned.Value = false
		local CurrentDamage = Instance.new("NumberValue", Conditions)
		CurrentDamage.Name = "CurrentDamage"
		CurrentDamage.Value = 0
	end)
end)
game.ReplicatedStorage.CombatEvents.Jab.OnServerEvent:Connect(function(Player, Action)
	local c = Player.Character
	if Action == "Jab1" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned").Value == true then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local CurrentDamage = v:FindFirstChild("Conditions"):FindFirstChild("CurrentDamage")
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						v.Humanoid:TakeDamage(3)
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.. "%"
						end
						wait()
					end
				end
			end
		end
	elseif Action == "Jab2" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned") then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local CurrentDamage = v:FindFirstChild("Conditions"):FindFirstChild("CurrentDamage")
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						v.Humanoid:TakeDamage(5)
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.. "%"
						end
					end
				end
			end
		end
	elseif Action == "Jab3" and not c:FindFirstChild("Conditions"):FindFirstChild("IsStunned") then
		for i, v in pairs(game.Workspace:GetChildren()) do
			if v:IsA("Model") and v:FindFirstChild("HumanoidRootPart") then
				local CurrentDamage = v:FindFirstChild("Conditions"):FindFirstChild("CurrentDamage")
				local vector = (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position)
				if vector:Dot( c.HumanoidRootPart.CFrame.lookVector ) < 0 then
					if (c.HumanoidRootPart.Position - v.HumanoidRootPart.Position).Magnitude < 5 then
						v.Humanoid:TakeDamage(10)
						if v:FindFirstChild("BillboardGui"):FindFirstChild("TextLabel") then
							v.BillboardGui.TextLabel.Text = CurrentDamage.. "%"
						end
					end
				end
			end
		end
	else
		return
	end
end)

The error is “ServerScriptService.JabServ:19: attempt to index nil with ‘FindFirstChild’”
Here is the dummy hierarchy, as well:

Please help!!

code is kinda messy to read but if it’s trying to find a folder then the dummy is probably nil

2 Likes

Hmm… Maybe its because I should have checked if they were in range and THEN checking if they have a folder? Since only specific dummy’s have humanoids, let me try that…

It worked! Problem was I forgot to check if they were in range 1st since I only have specific dummys the Conditions folder, thanks!

oh; glad i was able to help but uh maybe next time make sure ur code isn’t messier i had an eyesore reading that but that’s only me

my bad, ill make sure to edit my code to make sure it looks nicer for the future

1 Like

you should probably handle the action as a dictionary that’s how i do it

attacks = {
   Jab1 =  --do something here. create a function or call one from modulescript?
}

edit:it’s probably not worth it doing a function on dictionary cause it’s messier so just handle the attacks on module script.