Script error for a value

I keep getting this error with one of my games. The script is trying to find a value but it says its nil even tho it’s there

Script

	game.ReplicatedStorage.ServerEvents.DealDaTraps:FireClient(x,game.ReplicatedStorage.TrapAmounts:FindFirstChild(x.EquippedTrap.Value).Value, true)

script 2

game.ReplicatedStorage.ServerEvents.DealDaTraps.OnClientEvent:Connect(function(amount, val)
	
	if val == true then
		
		script.Parent.Visible = true
	
		local plr = game.Players.LocalPlayer
		local uis = game:GetService("UserInputService")
		
		local trapCount = amount
		
		script.Parent.Count.Text = trapCount
		
		local function PlaceTrap()
			game.Workspace.Bang:Play()
			if script.Parent.Visible == true then
				if trapCount >= 1 then
					local mentor = 0
					for i, v in pairs(game.Workspace.Map.Traps:GetChildren()) do
						if (v.Position - plr.Character.HumanoidRootPart.Position).Magnitude <= 5  then
							mentor = mentor + 1
						end
					end
					if mentor >= 1 then
					else
						game.ReplicatedStorage.LocalEvents.PlaceDaTrap:FireServer()
						trapCount = trapCount - 1
						script.Parent.Count.Text = trapCount
					end
				end
			end
		end
		
		script.Parent.Trap.MouseButton1Click:Connect(function()
			PlaceTrap()
		end)
		
		uis.InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.LeftControl then
				PlaceTrap()
			end
		end)
		uis.InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.LeftShift then
				PlaceTrap()
			end
		end)
		uis.InputBegan:Connect(function(key)
			if key.KeyCode == Enum.KeyCode.ButtonB then
				PlaceTrap()
			end
		end)
	else
		script.Parent.Visible = false
	end
	
end)
2 Likes

Would be helpful if you show your code next time.

1 Like

im right now adding my code to the post

1 Like

Hi, looking at your code, it seems like you are passing a value into the ‘FindFirstChild()’ function. FindFirstChild only works with strings, so make sure that the value of ‘x.EquippedTrap.Value’ is actually the value of a string.

1 Like

either x.EquippedTrap or x.EquippedTrap.Value IS nil not the value of x.EquippedTrap.Value, reading the error that is what it appears to be.

2 Likes

You should go about debugging and making sure that x.EquippedTrap.Value (assuming it’s a StringValue) exists in the code’s context.

1 Like